After reading through here and trying various options, I am finally able to get my custom post types 'testimonial' (created with product 'Toolset') to show along with my standard cat/tag queries WITHOUT the menu disappearing!! Here is the code I came up with, and placed in my theme's custom-functions.php file:
add_filter('pre_get_posts', 'query_post_type');
function query_post_type($query) {
if(is_category() || is_tag() || is_home() && empty($query->query_vars['suppress_filters'] ) ) {
$post_type = get_query_var('post_type');
if($post_type)
$post_type = $post_type;
else
$post_type = array('post','testimonial','nav_menu_item');
$query->set('post_type',$post_type);
return $query;
}
}
Being new to this I am not quite certain of how this is relating to the loop, and so of course now the problem is, when pulling my custom post types, on that same page a footer widget pulling from the same custom post type is delivering odd results, so it seems clear that I need to apply wp_reset_query(); or wp_reset_postdata(); - but my efforts to apply it are not working. I have tried it within the last container of the query itself, and in various theme locations. It has me wondering if I am really not doing it right, or there is instead a fatal flaw lurking in my code??? I am hoping someone can save me on this it has been so frustrating...
ADDENDUM - Updating this based on comments received...
If it helps others, I tried a few changes from suggestions below, but didn't follow them correctly at first... so for example was mixing '$query->is_category() || $query->is_tag()', etc with just 'is_main_query()' (duh) and seeing it fail assumed the latter addition was not helping... but then I read again and followed the complete suggestion applying the following:
add_filter('pre_get_posts', 'query_post_type');
function query_post_type($query) {
if($query->is_category() || $query->is_tag() || $query->is_home() && $query->is_main_query()) {
$post_type = get_query_var('post_type');
if($post_type)
$post_type = $post_type;
else
$post_type = array('post','testimonial');
$query->set('post_type',$post_type);
return $query;
}
}
... and it now appears to be working correctly! So just as stated below, not including $query-> into every one of the statement elements brought on the bad mojo!
It also seems that I am now able to eliminate the && empty($query->query_vars['suppress_filter'] as well as the addition of 'nav_menu_item' since the filter is now being applied to the proper location. Thanks much for the help with this.