• Resolved myladeybugg

    (@myladeybugg)


    I am hardcoding part of my sidebar and have added code to pull the most recent posts, but it is pulling drafts as well as published posts. How can I pull only published posts? Also, how can I limit the number of posts pulled?

    Here’s the code I have:

    <!--Recent Posts-->
    	 <h2<?php _e('Recent Posts'); ?></h2>
    <ul>
    <?php
        $recent_posts = wp_get_recent_posts();
        foreach( $recent_posts as $recent ){
            echo '<li><a href="' . get_permalink($recent["ID"]) . '" title="Look '.$recent["post_title"].'" >' .   $recent["post_title"]. '</a> </li> ';
        }
    ?>
    </ul>

    I’m running multisite with buddypress.

Viewing 1 replies (of 1 total)
  • Thread Starter myladeybugg

    (@myladeybugg)

    Fixed the issue using this code instead:

    <?php $recent = new WP_Query("showposts=10"); 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; ?>

Viewing 1 replies (of 1 total)
  • The topic ‘Pull Only Published Recent Posts in Sidebar’ is closed to new replies.