"In The Pipeline"/"Upcoming Posts" (3 posts)

  1. chaosfyregraphix
    Posted 6 years ago #

    Just curious...is it possible to have a sidebar item that can show upcoming posts ( Posts that have been written, but not yet published? ( IE: The one that you wrote earlier, and set to publish at a certain date.) )

    If so, how can I do this?

  2. thenameisnick
    Posted 6 years ago #

    Try something like this:

    function upcoming_posts() {
    	global $wpdb;
    	$sql = "SELECT * FROM wp_posts WHERE post_type = 'post' AND post_status = 'draft' ORDER BY 'ID' DESC";
    	$results = $wpdb->get_results($sql);
    	if ($results) {
    		echo '<ul>';
    		foreach ($results as $post): ?>
    			<li><a href="<?php echo get_permalink($post->ID); ?>"><?php get_the_title($post->ID); ?></a></li>
    		<?php endforeach;
    		echo '</ul>';

    Just copy that into your functions.php file and call it in your sidebar with:
    <?php upcoming_posts(); ?>

    Just threw it together, but it should work fine. It just makes a list of the post's permalinks, but it can be expanded to fit your needs. Let me know...

  3. chaosfyregraphix
    Posted 6 years ago #

    Thanks. I'll try it out as soon as I get a chance :)

Topic Closed

This topic has been closed to new replies.

About this Topic