admin管理员组文章数量:1291013
I have succeeded at limiting the posts on my homepage to ones in a homepage category that I created by implementing the following in functions.php:
function limit_category( $query ) {
if ( $query->is_home() && $query->is_main_query() ) {
$query->set( 'category_name', 'homepage' );
}
}
add_action( 'pre_get_posts', 'limit_category' );
This works fine for posts of type post, but I also have some posts of custom type event that have the category slug set to homepage that are excluded from the homepage.
To display events I am doing this:
function include_events( $query ) {
if( $query->is_main_query() && $query->is_home() ) {
$query->set( 'post_type', array( 'post', 'event') );
}
}
add_action( 'pre_get_posts', 'include_events' );
Is there a way I can also display event posts on the homepage when they have the homepage category?
本文标签: Apply category query clause to posts of custom type
版权声明:本文标题:Apply category query clause to posts of custom type 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741504399a2382233.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论