Support » Plugins » Hacks » Customize query (add_filter) with multiple loops

  • Hey guys,

    i have more than one Loops in my index.php (posts and featured tabs) and want the main loop to be filtered by extra fields. Both loops are generated via WP_Query and i already have a solution (without plugin). I could simple change the query submitted to the main-WP_Query (&metakey=XXX&metavalue=XXX).

    But i’m curious to know how it works with a plugin. I wrote the plugin using following filters “posts_where”, “posts_join” and “posts_groupby” and it works. Unfortunatelly it also applies this changes to the featured-area query.

    How can i differentiate between those queries and only apply the changes to the main-loop query?


Viewing 2 replies - 1 through 2 (of 2 total)
  • good question and i add this answer only to subscribe to this thread to follow replays 🙂

    maybe some combination with remove_filter? but how to remove filter only once?

    Any queries that you don’t want using the filter, pass them the suppress_filters parameter, this will basically create your query without any filters applied, filters such as post_where, posts_join and so on..

    'suppress_filters' => true

    NOTE: get_posts sets suppress_filters to true by default, where as query_posts and WP_Query both set this to false by default.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Customize query (add_filter) with multiple loops’ is closed to new replies.