WordPress.org

Ready to get started?Download WordPress

Forums

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

  1. Cristina
    Member
    Posted 3 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
    Member
    Posted 3 years ago #

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

    <ul>
     <?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; ?>
    </ul>

    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:
    &post_status=publish

    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
    Member
    Posted 3 years ago #

    Thanks works perfectly!

Topic Closed

This topic has been closed to new replies.

About this Topic