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

Otto otto at ottodestruct.com
Wed Apr 8 15:09:29 GMT 2009


On Tue, Apr 7, 2009 at 7:04 PM, Mike Schinkel
<mikeschinkel at newclarity.net> wrote:
> Jennifer,
>
> 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.

Sure there is. In order to get the Page, you have to run the query on
wp_posts. I assume you're using some internal tag in the post_content
to have it know which page to display the tweets on, after all.
Because that's the sanest way for a plugin to do it. Of course, you
could bypass that entirely and then use a page template instead, but
even then you need to query the posts table in order to know which
page template is being used.

> 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.

Actually, all of them require the posts table query, for the same
reasons I gave before. For any serious case where you're going to
display something special on a Page, then you need to have some way
for the system to know where to go and get that special thing. Just
because you don't happen to need the post_content doesn't mean that
the posts table query is entirely useless to you.

-Otto


More information about the wp-hackers mailing list