[wp-hackers] Any way to bypass $wp->query_posts()?

Mike Schinkel mikeschinkel at newclarity.net
Wed Apr 8 00:04:01 GMT 2009


Thanks for the reply. Unfortunately just replacing the query doesn't always make sense. 

Consider the following hypothetical use case: To display a page of latest Tweets from the site owner's Twitter account. A scheduled task could be called to retrieve tweets from the Twitter API and stored locally as HTML in wp_options table, and then the page displays the tweets by simply echoing the HTML to the browser.  For this use-case (and many similar ones), there is no need to run a query on wp_posts.

Another use case might be to pull users; running a query for posts only to discard the results in order to run a query for users makes little sense to me. A third use-case might be to display a page with a list of categories or tags, i.e. a query on the terms and taxonomy tables. A forth use-case might be to display a page with a list of links.  None of these require running a query in the posts table first.

To solve this dilemma shouldn't be that hard. I'm happy submit a patch, but as there are many ways to do it any of which could address the use cases I mention I'd like to get some input on the best way to do it. I'd rather not have to go through the process of submitting numerous similar patches each with a different approach and then wait to see which ones the core team decides to commit, if any.

-Mike Schinkel
Custom Wordpress Plugins

----- Original Message -----
From: "Jennifer Hodgdon" <yahgrp at poplarware.com>
To: wp-hackers at lists.automattic.com
Sent: Monday, April 6, 2009 10:22:55 AM GMT -05:00 US/Canada Eastern
Subject: Re: [wp-hackers] Any way to bypass $wp->query_posts()?

Mike Schinkel wrote:
>>> You could also use one of the hooks inside query_posts, to override 
> parts of the query, such as the where section, 
> Yeah, i guess I could do "WHERE 1=0" but it still sends the query to MySQL which is suboptimal.
>>> and I think even the whole query.
> AFAICT there's no way to bypass the query in that function. I've poured over that section of code for several hours now. Hoping that adding something to allow bypassing would be considered reasonable by those who options are most respected here.

Check out function WP_Query->get_posts() in wp-includes/query.php.

There is a filter called 'posts_request' that lets you replace the 
entire query.


Jennifer Hodgdon * Poplar ProductivityWare
Drupal, WordPress, and custom Web programming

wp-hackers mailing list
wp-hackers at lists.automattic.com

More information about the wp-hackers mailing list