How to disable main query?

Question

I don’t use The Loop, because I use different queries to fetch posts (I use 3 queries instead of one).

How to disable main query for home, category and search pages?

in progress 0
Stancell 6 months 1 Answer 364 views 0

Answer ( 1 )

  1. You want to do something like this
    add_filter( ‘posts_request’, ‘supress_main_query’, 10, 2 );
    function supress_main_query( $request, $query ) {
    if ( $query->is_admin ) {
    return $request;
    }
    if ( $query->is_main_query() && ( $query->is_home() || $query->is_seach() || is_category() ) ) {
    return false;
    } else {
    return $request;
    }
    }

Leave an answer