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

Mike Schinkel mikeschinkel at newclarity.net
Mon Apr 6 03:52:29 GMT 2009


Jennifer: 

Thanks for the response.

>> Exit on init()

Yeah, I really don't want to do that. The unintended consequences of not running code that expects to be run by core or other plugins could be significant.

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

-Mike Schinkel
Custom Wordpress Plugins
http://mikeschinkel.com/custom-wordpress-plugins

----- Original Message -----
From: "Jennifer Hodgdon" <yahgrp at poplarware.com>
To: wp-hackers at lists.automattic.com
Sent: Sunday, April 5, 2009 11:29:46 PM GMT -05:00 US/Canada Eastern
Subject: Re: [wp-hackers] Any way to bypass $wp->query_posts()?

You could do something in the init() action of your plugin, where for 
a particular URL, you can do whatever you want and then exit, 
bypassing all the rest of WP's default actions.

You could also use one of the hooks inside query_posts, to override 
parts of the query, such as the where section, the join section, and I 
think even the whole query.

    --Jennifer

Mike Schinkel wrote:
> I hope what I'm about to ask isn't viewed as heresy, but I've been building a CustomUrls plugin and am finding that AFAICT WordPress always runs a query for posts no matter if its needed or not, i.e. here is $wp->main() : 
> 
> function main($query_args = '') { 
> $this->init(); 
> $this->parse_request($query_args); 
> $this->send_headers(); 
> $this->query_posts(); 
> $this->handle_404(); 
> $this->register_globals(); 
> do_action_ref_array('wp', array(&$this)); 
> } 
> 
> I would like to be able to disable $wp->query_posts() in cases where I want to run a custom query. Is there a way to do this that I'm just not seeing, or if not is there a reason why it wouldn't make sense to allow bypassing or $wp->query_posts() somehow (and $wp->handle_404() too, for that matter)? 

-- 
Jennifer Hodgdon * Poplar ProductivityWare
www.poplarware.com
Drupal, WordPress, and custom Web programming

_______________________________________________
wp-hackers mailing list
wp-hackers at lists.automattic.com
http://lists.automattic.com/mailman/listinfo/wp-hackers


More information about the wp-hackers mailing list