一切工作在我的代码旁边posts_per_page(它将显示的帖子数量)。这里是我的WordPress的部分代码:posts_per_page不起作用
<?php
$category = get_the_category();
$current_category = $category[0]->term_id;
$qarr = array(
'posts_per_page' => $posts_number,
'cat' => $current_category,
'tag' => 'pinned', // tag filtered
'post__not_in' => array(get_the_ID())
);
$q = new WP_Query($qarr);
if($q->have_posts()) : while ($q->have_posts()) : $q->the_post();
?>
为什么它不工作?我已阅读文档并不明白问题所在。
以下是完整的代码,如果你想查看和测试它,只需设置为$ posts_number一个数字:http://pastebin.com/uNsynNiM
posts_per_page的默认值是5.如果您要完全删除posts_per_page参数,是否有5个帖子返回查询?如果不是,则没有足够的帖子来满足posts_per_page标准。尝试将其设置为低数字(如2)。你有2个职位?你得到2以上?您是否拥有符合查询条件的最少2篇文章? – maiorano84
@ maiorano84我确实将posts_per_page设置为1,并且它返回了多个 - 这意味着它不能正常工作?随意查看我链接的完整代码,这是一个简短的脚本,您可以轻松测试。 –
我也注意到,在这个版本中,您已将查询的标签从“特色”更改为“固定”。你是否有超过一个邮政标签'固定'? – maiorano84