posts_per_page is set to 1, returns 50 posts

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 echoed the SQL from $query->request, and I can see that the LIMIT is set to 50:

Read More
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?

Related posts

Leave a Reply

1 comment

  1. try

    $query = new WP_Query(array(
        'post_type'         => 'some_custom_post_type',
        'posts_per_page'    => 1,
        'showposts'         => 1,
        'orderby'           => 'date',
        'order'             => 'DESC'
    ));