I’m trying to get the latest post in a custom post type:
$query = new WP_Query(array(
'post_type' => 'some_custom_post_type',
'posts_per_page' => 1,
'orderby' => 'date',
'order' => 'DESC'
));
For some weird reason, this returns 50 posts. I echo
ed the SQL from $query->request
, and I can see that the LIMIT
is set to 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
Switching post_limits
instead of posts_per_page
yields the same weird result.
Why is this happening, and how can I fix it?
try