I’m doing some de-bugging on a theme I’m working on and I’m hoping someone can help me please.
I used this function that Justin Tadlock made to display custom post types on the blog page and with wp-debug set to true I get a Notice: Undefined index: suppress_filters message.
The code is as follows:
// Custom Post Type for the public blog posts to show on Index or blog page
add_filter( 'pre_get_posts', 'my_get_posts' );
function my_get_posts( $query ) {
if ( ( is_home() && false == $query->query_vars['suppress_filters'] ) || is_feed() )
$query->set( 'post_type', array( 'news', 'attachment' ) );
return $query;
}
If anyone could help that would be great.
Thanks
If
$query->query_vars['suppress_filters']
is not set you will get that message.Use
empty($query->query_vars['suppress_filters'])
instead offalse == $query->query_vars['suppress_filters'] )
or use$query->get('suppress_filters')
like thisfalse == $query->get('suppress_filters')
.Untested (minimally tested) but I believe either of those should give you the same results minus the notice.
Sounds like
$query->query_vars['suppress_filters']
isn’t set. Try this:I added a check to make sure that
$query->query_vars['suppress_filters']
is actually set before you check to see if it’sfalse
. (Also I broke up theif()
statement for easier reading. (I think I’ve matched up all the(
and)
correctly.)