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> ‘; }
The problem occurs when you have multi author blog, If someone submit article for review this script my delete this post?, Just wondering whats your thought?
Navin – Not necessarily with a multi author blog. Sometimes I line up my posts for publishing with a time gap of 12hrs or a day even. So when they are still in the draft stage, you can still see them up on the Recent Posts widget.
Thanks for the help! Very straight forward and helpful. 🙂 Enjoy your weekend
Thanks Rochelle and you too have a great weekend…
Hi Praveen,
I can see where this would be very irritating for sure. I don’t believe I’ve run across this before and I’m thankful that I haven’t. I wouldn’t have known what to do to be honest with you. Thanks for this tip, I’m sure others will find it very helpful.
~Adrienne
Hi Adrienne – Welcome to my blog, and it is really nice to have you here. I am glad you didnt run into this problem, believe me, I was in a bad situation myself.