WordPress.org

Forums

Customize query (add_filter) with multiple loops (3 posts)

  1. harlekinx
    Member
    Posted 4 years ago #

    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?

    thxs.

  2. kkarpieszuk
    Member
    Posted 4 years ago #

    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?

  3. Mark / t31os
    Moderator
    Posted 4 years ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Topic