我正在尝试以自定义帖子类型获取最新帖子:
$query = new WP_Query(array(
'post_type' => 'some_custom_post_type',
'posts_per_page' => 1,
'orderby' => 'date',
'order' => 'DESC'
));
出于某种奇怪的原因,这会返回50个帖子。我echo
编辑了来自$query->request
的SQL,我可以看到LIMIT
设置为50:
SELECT SQL_CALC_FOUND_ROWS wp_posts.ID
FROM wp_posts
WHERE 1=1
AND wp_posts.post_type = 'some_custom_post_type'
AND (
wp_posts.post_status = 'publish'
OR wp_posts.post_status = 'private'
)
ORDER BY wp_posts.post_date DESC
LIMIT 0, 50
切换post_limits
代替posts_per_page
会产生同样奇怪的结果。
为什么会发生这种情况,我该如何解决?
答案 0 :(得分:0)
试
$query = new WP_Query(array(
'post_type' => 'some_custom_post_type',
'posts_per_page' => 1,
'showposts' => 1,
'orderby' => 'date',
'order' => 'DESC'
));