
//自定义类型文章在首页和搜索页展示
if ( (is_home() || is_search()) && $query->is_main_query() )
$query->set( 'post_type', array('post', 'product' ) ); //只显示product
// $query->set( 'post_type', array( 'shuoshuo', 'product' ) ); //主循环中显示shuoshuo和product
return $query;
}
add_action('pre_get_posts','ashuwp_posts_per_page');
pre_get_posts
钩子,不光可以实现这一点,你还可以自由发挥,改变主循环的其它一些参数,具体请查阅官方函数说明。