php - 每页帖子不限制查询中的帖子
问题描述
我有一个查询吐出没有特色的帖子,但由于某种原因posts_per_page
限制器不起作用......
<?php $featured_posts = get_posts( [
'posts_per_page' => 3,
'orderby' => 'date',
'order' => 'DESC',
'update_post_term_cache' => false,
'update_post_meta_cache' => false,
'meta_key' => '_is_ns_featured_post',
'meta_value' => 'yes',
'fields' => 'ids',
] );
query_posts( array( 'post__not_in' => $featured_posts ) );
while ( have_posts() ) : the_post();?>
<div class="news-item-block col-md-4" role="article">
<a class="news-item-image-link" href="<?php the_permalink(); ?>">
<?php the_post_thumbnail('news-grid-image'); ?>
</a>
<span class="news-item-date"><?php the_date( 'M d, Y' ); ?></span>
<a class="news-item-title" href="<?php the_permalink(); ?>">
<h1><?php the_title(); ?></h1>
</a>
</div>
<?php endwhile;
wp_reset_query();
?>
感谢您对此问题的任何见解。
解决方案
是的,使用'nopaging' => true
和'ignore_sticky_posts'=>true
<?php $featured_posts = get_posts( [
'posts_per_page' => 3,
'orderby' => 'date',
'order' => 'DESC',
'update_post_term_cache' => false,
'update_post_meta_cache' => false,
'nopaging' => true,
'ignore_sticky_posts'=>true,
'meta_key' => '_is_ns_featured_post',
'meta_value' => 'yes',
'fields' => 'ids',
] );
query_posts( array( 'post__not_in' => $featured_posts ) );
while ( have_posts() ) : the_post();?>
<div class="news-item-block col-md-4" role="article">
<a class="news-item-image-link" href="<?php the_permalink(); ?>">
<?php the_post_thumbnail('news-grid-image'); ?>
</a>
<span class="news-item-date"><?php the_date( 'M d, Y' ); ?></span>
<a class="news-item-title" href="<?php the_permalink(); ?>">
<h1><?php the_title(); ?></h1>
</a>
</div>
<?php endwhile;
wp_reset_query();
?>
推荐阅读
- javascript - chartjs-plugin-annotation 无法在折线图的 y 轴上进行自动调整
- assembly - 在 6 个寄存器中找到最大值,汇编 X86
- javascript - IOS 上的 PWA 推送通知
- azure - Ansible如何从字典列表中找出字典
- apache-kafka - kafka-avro-console-consumer + 'bootstrap-server' 不是公认的选项
- firewall - 无法使用 ngrok 完成隧道连接错误
- java - 如何拆分java spring以使用存储库
- nginx - 如何在 nginx 中注册反向代理 webhook?(shopify 网络钩子)?
- javascript - 如何检测文档中的元素移动(改变位置)?
- c# - 如何一次选择 Listview 中的所有项目或从每一行获取每个主键?