[wp-hackers] pre_get_posts problem

Krusty Ruffle krustyruffle at rustykruffle.com
Mon Aug 9 08:05:48 UTC 2010


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

The conditionals I use with pre_get_posts look like:

if ( !is_admin() && is_home() || is_author() || is_date() ) :

Honestly, the pre_get_posts would probably work fine for my current
situation as I am using only a single loop with none of the new menu stuff
and nothing else that I can think of would cause problems with it, but I
would still like to find a 'proper' solution as pre_get_posts feels pretty
hackey even to me. I am beginning to think that it cannot be done properly
with a plugin and may need to have an entire theme written around it, or at
least a custom loop written specifically for it, but I haven't had the
chance to look into that either.

Thank you for reading and trying to help with this though, I do appreciate
it!

On Mon, Aug 9, 2010 at 12:03 AM, Mike Schinkel
<mikeschinkel at newclarity.net>wrote:

> Have you tried adding an is_home() to your if() and using your own
> preferred array of post types?  (If you'll read through the code I would
> hope it's reasonably obvious that it would only work for author and search
> pages.)
>
>


More information about the wp-hackers mailing list