Disable the MySQL query in the main query

I would like to disable the MySQL portion of the main query, i.e. I want every step to be followed on this page EXCEPT step 4.3: http://codex.wordpress.org/Query_Overview

What’s the easiest way to go about doing that?

Related posts

2 comments

  1. Check if this solution work for your case:

    add_filter('posts_request', 'supress_main_query', 10, 2);
    function supress_main_query( $request, $query ){
        if( $query->is_main_query() && ! $query->is_admin )
            return false;
        else
            return $request;
    }
    

    posts_request is the last filter called before running the query, and pass to you the $requestvariable with the generated SQL string and $query, with the WP_query object used to generate the query.

    This way you can check if this is the main query, and return false to don’t run the generated query.

  2. It typically hard to throw out completely thing that WP insist on doing during core load process. It is however relatively easy to mess with them in smaller ways and sufficient results.

    Query has a lot of filters, namely posts_where (with is_main_query() check to be sure we are only modifying it) allows us to change WHERE part of SQL query.

    But what do we add to it to get rid of it? Typically following condition is used AND 1=0. Since it’s very obviously not satisfiable it efficiently short circuits SQL query into no results.

Comments are closed.