如何解决多种职位类型,但仅设置一种职位
我正在显示多种帖子类型,但我想为其中一种帖子类型设置偏移量,但是我该怎么做?
$args = array(
'post_type' => array('wins','memes'),'posts_per_page' => '5',//'offset' => '1',(with this i set the offset for both but i only want to set it for one of them.)
'post_status' => 'publish'
);
解决方法
您可以收集不需要的ID。如果您不需要带有偏移量的帖子类型的特定订单,而只是从该类型中查找5个最新帖子。您可以执行以下操作:
<?php
$posts_to_exclude = array();
$args = array(
'post_type' => 'wins',// post type you want to offset
'numberposts' => 5 // the default is 5,but you can add for good measure
);
$posts = get_posts( $args );
if ($posts) {
foreach ($posts as $post) {
$posts_to_exclude[] = $post->ID;
}
}
$args = array(
'post_type' => array('wins','memes'),'posts_per_page' => '5','post__not_in' => $posts_to_exclude,'post_status' => 'publish'
);
new WP_Query( $args );
// Do more stuff....
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。