admin管理员组文章数量:1130349
I'm in a situation where I have to exclude certain posts dynamically using a complex set of conditions*. I'm currently using the_posts filter to remove posts that don't meet the condition.
add_filter( 'the_posts', function( $posts, $query ) {
foreach ( $posts as $i => $post ) {
if ( check_custom_conditons( $post->ID ) ) {
unset( $posts[ $i ] );
}
}
return $posts;
}, 10, 2);
Problem is each page has an irregular number of posts as some of them were excluded after the query was run. Is it possible to maintain the same number of posts per page after excluding certain posts?
* The condition checks the parent category of the post for other posts with similar attributes and returns true if found and false if not found. I can't find a way to do this before the query is run.
I'm in a situation where I have to exclude certain posts dynamically using a complex set of conditions*. I'm currently using the_posts filter to remove posts that don't meet the condition.
add_filter( 'the_posts', function( $posts, $query ) {
foreach ( $posts as $i => $post ) {
if ( check_custom_conditons( $post->ID ) ) {
unset( $posts[ $i ] );
}
}
return $posts;
}, 10, 2);
Problem is each page has an irregular number of posts as some of them were excluded after the query was run. Is it possible to maintain the same number of posts per page after excluding certain posts?
* The condition checks the parent category of the post for other posts with similar attributes and returns true if found and false if not found. I can't find a way to do this before the query is run.
本文标签: paginationExcluding posts without affecting the number of posts per page
版权声明:本文标题:pagination - Excluding posts without affecting the number of posts per page 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/questions/1749057990a2309655.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


发表评论