[wp-hackers] Any way to bypass $wp->query_posts()?
Otto
otto at ottodestruct.com
Wed Apr 8 21:19:07 GMT 2009
The query *is* WordPress. It's the whole backbone of the thing. If
you're operating outside the query, then why ever even bother to load
WordPress at all?
For your custom-URL idea, you'd be better off adding a filter onto
mod_rewrite_rules, and appending your own rules in front of it, to
directly load your own PHP on that URL. Then your URL never even loads
WordPress. No query, no nothing. It'd be easy enough to do.
RewriteRule YOUR_URL PATH_TO_YOUR_PHP_FILE [L] and you're done.
Just hook a filter onto mod_rewrite_rules, stick your own rules in
(generated from your config, I assume), make a call to
save_mod_rewrite_rules(), and voila. The .htaccess gets updated and
you're golden.
-Otto
On Wed, Apr 8, 2009 at 1:07 PM, Mike Schinkel
<mikeschinkel at newclarity.net> wrote:
> "Otto" <otto at ottodestruct.com> wrote:
>> 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.
>
> Thanks for the reply.
>
> Yes you'd be right when making all the standard assumptions for a WordPress site. However, I'm writing a plugin that bypasses those assumptions.
>
> BTW, when you say "internal tag" what specifically do you mean? A pagename? An actual tag? Something else?
>
>> 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.
>
> Actually, I'm bypassing page templates completely, using template_redirect, and setting new rules in WP_Rewrite. (And Chris Jean recently battled[1] with this same type of thing so it is not just me.)
>
> My plugin allows a themer or plugin developer to define any arbitrary URL they want to have processed and have it routed to run whatever they want to run. Basically it lets a themer or plugin dev start a page with a (mostly) clean slate. With this plugin and in some use-cases running get_posts() makes no sense because the process flow never makes it to running a page template or even any of the "if" logic template-loader.php.
>
> To address these use-cases there is simply the need to bypass running the query in /wp-include/classes.php (I added the one line "if (!$this->bypass_query)"):
>
> function main($query_args = '') {
> $this->init();
> $this->parse_request($query_args);
> $this->send_headers();
> if (!$this->bypass_query)
> $this->query_posts();
> $this->handle_404();
> $this->register_globals();
> do_action_ref_array('wp', array(&$this));
> }
>
> BTW, one thing I am finding is that the concept of using WP_Rewrite is far from fleshed-out. There are many places in WordPress where the "type" of a URL is hardcoded in implicit fashion. The most recent example I found was in wp_title(). wp_title() makes a bunch of assumptions but doesn't give the 'wp_title' hook any context to know what it's operating on so you can't really generate an appropriate title for your URL. Thus even though people on this list say "The right way to do handle custom URLs is via WP_Rewrite" the reality is that logic path has never been tested and has many issues. I'd like to eventually address all of those by providing a "custom URL" escape valve in all relevant contexts, but for now I'd like to just be able to bypass running the query.
>
> -Mike Schinkel
> Custom Wordpress Plugins
> http://mikeschinkel.com/custom-wordpress-plugins
>
> [1] http://www.nabble.com/Showing-custom-page-types-td21733174.html
> _______________________________________________
> 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