Support » Developing with WordPress » WordPress integration is showing scheduled posts on my webite

  • Resolved sonictempest

    (@sonictempest)


    Hello,

    I’ve been using this neat snippet of code to integrate wordpress with my non-wordpress website and it’s been doing wonders for me.

    <?php
    define('WP_USE_THEMES', false);
    require('blog/wp-blog-header.php');
    ?>
    <?php
    
    $number_of_posts = 5;
    $args = array( 'numberposts' => $number_of_posts );
    $recent_posts = wp_get_recent_posts( $args );
    foreach( $recent_posts as $recent_post ){
    echo "<span>".$recent_post['post_date']."</span> <br>";
    echo "<h3>".$recent_post['post_title']."</h3>";
    echo  "<p>".$recent_post['post_content']."</p><br><br>";
    
    }
    
    ?>

    However, even the scheduled posts that are not supposed to show… well… they show up anyway on the main page. I’ve tried a loda of different methods but don’t seem do get it to work correctly.
    Is there any way to make it so my scheduled posts not show up until the scheduled date using this method?
    Thanks in advance!

    • This topic was modified 1 year, 9 months ago by sonictempest.
    • This topic was modified 1 year, 9 months ago by sonictempest.

    The page I need help with: [log in to see the link]

Viewing 2 replies - 1 through 2 (of 2 total)
  • Dion

    (@diondesigns)

    Try the following (optimized) code and let me know if it works the way you want:

    <?php
    require('blog/wp-load.php');
    
    $recent_posts = wp_get_recent_posts(['numberposts' => 5, 'post_status' => 'publish']);
    foreach($recent_posts as $recent_post) {
    	echo "<span>{$recent_post['post_date']}</span><br>";
    	echo "<h3>{$recent_post['post_title']}</h3>";
    	echo "<p>{$recent_post['post_content']}</p><br><br>";
    }
    Thread Starter sonictempest

    (@sonictempest)

    Worked like a charm!

    Sorry about the delay!

    Thank you so much!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘WordPress integration is showing scheduled posts on my webite’ is closed to new replies.