[resolved] List of Recent Posts Showing Drafts and Scheduled Posts (3 posts)

  1. Cristina
    Posted 4 years ago #

    I'm using WordPress's built-in function to display the 5 most recent posts in my sidebar, rather than causing more bloat by installing the "Recent Posts" plugin. However, amongst my recent posts it lists drafts and posts scheduled for later dates. How do I get it so it just lists my recent public posts?

  2. Jordan
    Posted 4 years ago #

    You could just use a query to pull in recent posts :).

     <?php $recent = new WP_Query("showposts=5"); while($recent->have_posts()) : $recent->the_post();?>
    	<li><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_title(); ?></a></li>
     <?php endwhile; ?>

    You can use a bunch of different parameters within that query too: http://codex.wordpress.org/Function_Reference/query_posts#Parameters

    If you still see your drafts/unscheduled posts, you can add in the following parameter:

    You could also alter it to use "future", "pending", "draft" and a bunch of others (http://codex.wordpress.org/Function_Reference/query_posts#Type_.26_Status_Parameters).

  3. Cristina
    Posted 4 years ago #

    Thanks works perfectly!

Topic Closed

This topic has been closed to new replies.

About this Topic