voceconnect / lift-search

Lift Search for WordPress
14 stars 12 forks source link

Taxonomy fix #66

Closed TELUS-Alexander closed 10 years ago

TELUS-Alexander commented 10 years ago

Hi,

We have been using your plugin and its quite good out of the box, thank you.

The issue came when we needed to filter something by taxonomy. We followed your documentation, which did suggest the correct solution, but it was still not working. Our taxonomy was cities and it is text based.

When we did a search Lift was querying the taxonomy, but still the results were not being filtering.. after endless hours of debugging it came down to lift setting the taxonomy terms as typed where as they need to be lower case.

We did a slight hack to bypass this and everything works as expected:

<?php function Lift_ModifyTaxonomies($query) { if( is_admin() || !$query->is_main_query() || !$query->is_search ) return $query;

$tax_queries = $query->tax_query->queries;

foreach( $tax_queries as $query_index => $tax_query )
{
    // if terms are id based then no need to lowercase them
    if( 'id' == $tax_query['field'] )
        continue;

    foreach( $tax_query['terms'] as $term_index => $term )
    {
        $tax_query['terms'][$term_index] = strtolower($term);
    }

    $tax_queries[$query_index] = $tax_query;
}

$query->set('tax_query', $tax_queries);

}

add_filter('pre_get_posts','Lift_ModifyTaxonomies'); ?>

We hope this comes helpful to anyone until it gets fixed in the plugin.

kevinlangleyjr commented 10 years ago

You should be passing in the slug of the term into the query, not the actual name of the term. That should solve the issue you are having here.