[wp-hackers] pre_get_posts problem

Krusty Ruffle krustyruffle at rustykruffle.com
Mon Aug 9 01:10:46 UTC 2010


I'm trying to add a custom post type on the main index, author index, and
date indexes. This doesn't seem to work on the main index.

The only thing I've been able to get to work right is 'pre_get_posts' which
is supposed to be the wrong way to do it. I am lost and growing frustrated,
I understand why 'pre_get_posts' is wrong but have been unable to get any of
the suggested alternatives to work...

Try this and let me know if it solves your problem:
>
> add_filter( 'parse_query', 'my_parse_query' );
> function my_parse_query( $query ) {
>        $q = $query->query;
>        $is_menu = (isset($q['post_type']) &&
> $q['post_type']=='nav_menu_item');
>        if (!$is_menu && ((is_author() && isset($q['author_name']) ||
> (is_search() && isset($q['s']))))) {
>                $query->query_vars['post_type'] = array( 'post',
> 'nav_menu_item', 'lesson', 'howto', 'workshop', 'attachment' );
>        }
> }
>
>
> -Mike
> _______________________________________________
> 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