Query Multiple Taxonomies
How to keep this from overriding custom get_posts queries (5 posts)

  1. goldenapples
    Posted 6 years ago #

    I just installed this plugin to help me improve the search functions on a site I'm working on. Included fields for a couple custom taxonomies in the search form along with the "s" input. That works fine.

    The problem is, now all of my pages which rely on custom get_posts or WP_Query queries started returning everything. I added a line to the function pre_get_posts() like this :

    if (!is_search()) return; //ie only add this processing on search pages

    Seems to function the way I want. I can't tell if there's a better way of doing this, though. And... should this plugin be overriding custom queries that include taxonomy queries to begin with?

  2. scribu
    Plugin Author

    Posted 6 years ago #

    Please paste an example of a custom query that's causing problems.

  3. goldenapples
    Posted 6 years ago #

    My query looks like this:

    $posts = get_posts('category='.$cat.'&location='.$city.'&orderby=date&order=DESC');

    where "location" is a custom taxonomy, and one of the taxonomies I have included in the drilldown widget. But without the hack I mentioned above, this query seems to return results from all "locations", not just the one passed in the arguments.

    Just wondering if this was intended behavior, and if so, if there's a better way of overriding it than what I've done. Thanks!

  4. scribu
    Plugin Author

    Posted 6 years ago #

    'category' should be either 'cat' (id) or 'category_name' (slug).

  5. goldenapples
    Posted 6 years ago #

    Thanks. I fixed that one. Still, it was functioning as I expected it to... for now, 'category' is maintained for backwards compatability.

    But the result of the query is still the same when I make that fix. Unless I explicitly disable the pre_get_posts function from QMT_Query on everything but search results, it overrides the taxonomy arguments passed in my get_posts query. No big deal, I've worked around it though.

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Query Multiple Taxonomies
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic