How To Brew

How to Remove Draft Posts from your Recent Posts

A few weeks back, I redesigned my plain looking footer to include Popular Posts, Categories, Most Recent Posts and also all the other websites & blogs where my article has been featured(All those bloggers have been kind enough to send me a logo to reuse on my site).

I didnt realize this at first, but one of my readers pointed out that some of my posts are not available. Since then I have been looking all around my site to see what may have been leading to a 404 page on my site, and until yesterday I couldnt figure out that my “Recent Posts” section was also displaying the posts that I have in a “draft” stage for future publishing.

This was really embarrassing to let my readers think I have published a particular article when I havent yet completed the same. So I started looking around to fix this and found it was pretty simple to filter out the non-published ones from appearing here.

If you are facing a similar problem, you can use the code below to rectify the issue.

$number_recents_posts = 5;
$args=array(‘numberposts’ => $number_recents_posts,’post_status’=>’publish’);
$recent_posts = wp_get_recent_posts($args); foreach( $recent_posts as $recent ){ echo ‘<li><a href=”‘ . get_permalink($recent[“ID”]) . ‘” title=”Look ‘.$recent[“post_title”].'” >’ . $recent[“post_title”].'</a> </li> ‘; }

About the author

Praveen Rajarao

Praveen Rajarao is an Entrepreneur and in his spare time blogs on his website – and His topics range from blogging to technology to affiliate programs and making money online and how-to guides. Daily Morning Coffee is also accepting Guest Posts from Professional Bloggers at this time, take a look at “Write For DMC” page for more details on the same.


Click here to post a comment

CommentLuv badge

This blog uses premium CommentLuv which allows you to put your keywords with your name if you have had 3 approved comments. Use your real name and then @ your keywords (maximum of 2)

Like DMC on FB

Get your Keurig Starter Kit Today! 50% off coffee makers +25% off beverages + free shipping, Shop Now!

Recent Comments