Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm using get_posts to generate a list of posts.

$args = array(
    'post_type'     => 'post',
    'numberposts'       => -1,
    'post_status'       => array('publish'),
    'orderby'       => 'post_date',
    'order'         => 'DESC',
    'suppress_filters'  => false
);

$posts = get_posts( $args );

However, the list includes posts named "Auto-Draft", even though I do not include them in the 'post_status' parameter. As far as I read those Auto-Drafts should be only existing for 7 days, but the posts that show up in the list are far older than 7 days.

Anything I'm missing? Thanks!

share|improve this question
1  
I do not get auto-drafts when I run that code. I suspect that your theme or a plugin is applying a filter. Disable your plugins and switch themes. See if you can isolate the issue. –  s_ha_dum Jul 16 '13 at 19:47
    
Hey s_ha_dum, thanks. I already tried that and even with all plugins disabled and Twenty Twelve theme it does list "Auto draft" posts. –  Alphawolf Jul 17 '13 at 17:37
    
Seems that you got revisions in your post types array. Check that. –  kaiser Mar 21 at 2:33
add comment

1 Answer

If you just want to return published posts, you can exclude the 'post_status' argument as by default it will just return published posts only.

Having said that, the array works for me too though.

share|improve this answer
1  
If the user is already explicitly asking for only published posts, why would relying on the default value (which is actually inherit) result in only published posts being returned? –  Dan Mar 21 at 1:01
    
If you check the documentation for get_posts at codex.wordpress.org/Template_Tags/get_posts, you'll see that the default usage of get_posts specifies: 'post_status' => 'publish' So your down votes are both incorrect and unwarranted. –  Matty J Mar 21 at 2:53
    
The codex is wrong, but I was partially wrong too. The default is based on whether the post is an attachment (inherit) or not (publish). That said, inherit being the default was not my primary point. My point was that relying on the default setting when when the current explicit setting is equivalent will not solve anything. –  Dan Mar 21 at 3:51
    
Ok well whether it is 'inherit' or 'publish' what I have stated does work and does solve the OP's question so it is therefore a correct answer to the question at hand, so it both should not be down-voted and to be honest also trumps any 'point' someone might want to make and solves a lot more than an unconstructive downvote. Not only that it is less code and is arguably therefore a better solution to the problem. Additionally I stated that the array does work, which should lead the OP to the conclusion that the problem lies elsewhere, whether he takes the array approach or omits the parameter. –  Matty J Mar 21 at 4:37
    
the point is to answer the question. Omitting an optional parameter doesn't resolve the question of why Auto-Draft values older than 7 days are being returned. I'm not trying to be pedantic. I downvoted not because of what the default value is, but because the question is not answered. –  Dan Mar 21 at 4:49
show 2 more comments

Your Answer

 
discard

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.