[wp-hackers] pre_get_posts problem

Mike Schinkel mikeschinkel at newclarity.net
Tue Aug 3 22:54:54 UTC 2010

On Aug 3, 2010, at 6:26 PM, Angelia Baladon wrote:
> I see that Justin Tadlock has updated his post regarding the use of
> pre_get_posts and the code is now:
> add_filter( 'pre_get_posts', 'customtype_get_posts' );
> function customtype_get_posts( $query ) {
>    if ( is_author() && false == $query->query_vars['suppress_filters'] )
>        $query->set( 'post_type', array( 'post', 'howto', 'lesson' ,'attachment' ) );
>    return $query;
> }

Why that works is that the nav_menu_items query suppresses filters.  Unfortunately it will still be global for the author page so if, for example you had a widget that displayed only "lessons" in the sidebar the above would cause your widget to display posts, howtos, lessons and attachments in its widget.

Ah the downside of global scoping...


More information about the wp-hackers mailing list