Tell me more ×
WordPress Answers is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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:

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?

share|improve this question
Can you give me some more information like in which template you have used this query? the code before and after the query and have you added any code in theme to control posts_per_page? – Vinod Dalvi Mar 13 at 5:34
add 'suppress_filters' => true to WP_Query argument. – Jesse Mar 13 at 6:29
@all - I have no other filters. Adding 'suppress_filters' => true doesn't change anything. – MegaHit Mar 13 at 17:28

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.