[wp-hackers] pre_get_posts problem

Mike Schinkel mikeschinkel at newclarity.net
Tue Aug 10 13:02:28 UTC 2010


On Aug 9, 2010, at 4:05 AM, Krusty Ruffle wrote:
> I'm sorry, I was tired when I sent that last email and was not really very
> clear. I did not just do a copy/paste of the code provided, I tried the
> following to make sure it would work before I even tried adding the post
> types.
> 
> add_filter( 'parse_query', 'my_parse_query' );
> function my_parse_query( $query ) {
>      print_r( $query ); die();
> }
> 
> This causes me to get a page with nothing but the $query on most pages
> however, It does nothing on the blog index.

You've got something else going on in your system with other plugins or something. You'll have to track that does first.  Try disabling other plugins.

> The main blog index still loads a page with only the built in post types on it.
> This leads me to believe that the 'parse_query' action is not being called there.

It sounds like it is being called but $query contains nothing it seems.  Try this to see if "We're Here" shows up.

add_filter( 'parse_query', 'my_parse_query' );
function my_parse_query( $query ) {
     echo "We're Here!";
     print_r( $query ); die();
}

> Looking at the
> source code on lines 1548 & 1549 of query.php shows that the action does
> indeed depend on an if() statement. Unfortunately parse_query() is a rather
> long function and I was too tired to concentrate properly so I have not read
> through it well enough to fully understand what it's doing or why it might
> not be called.

Want to figure it out without having to "mentally execute" the code?  Get an IDE w/debugger (I use PhpStorm+XDEBUG.)

-Mike


More information about the wp-hackers mailing list