WordPress.org

Ready to get started?Download WordPress

Forums

Latest Post Excludes Scheduled Post (3 posts)

  1. technguide
    Member
    Posted 1 year ago #

    Hi, i am creating a link to grab the latest post from my blog.

    It works, but it didn't hide the posts i've scheduled for a later time/date. What should i edit? Is it 'excludable'? I'm connecting to the database to delete the autodrafts.

    <?php require('../wp-blog-header.php');?>
    <html>
    	<?php
    		define('dbName', '********');
    		define('dbUser', '********');
    		define('dbPassword', '********');
    		define('dbHost', '********');
    
    		$dbc=mysqli_connect(dbHost, dbUser, dbPassword, dbName);
    		$sql="delete from <code>wp_posts</code> where <code>post_status</code> = 'auto-draft'";
    		$result = mysqli_query($dbc, $sql);
    		mysqli_close($dbc);
    		?>
    
        <?php
            $args = array( 'numberposts' => 1,
                          'post_status'=>"published",
                          'post_type'=>"post",
                          'exclude'=>"uncategorized",
                          'exclude'=>"future",
                          'orderby'=>"post_date");
            $postslist = get_posts( $args );
    
            foreach ($postslist as $post) : setup_postdata($post);
            ?>
        Redirecting to <b>
        <?php
            echo the_permalink();
            echo "</b>. ";
            ?>
        If redirection doesn't take place within 5 seconds, click
        <a href = "<?php the_permalink()?>">here</a>.
        <br/><br/>
        <b>Post Name</b> : <?php the_title();?><br/>
        <b>Date Posted</b> : <?php the_date();?><br/>
        <script>
        location = "<?php the_permalink()?>";
        </script>
        <?php endforeach; ?>
    </html>
  2. IMICreation
    Member
    Posted 1 year ago #

    'post_status'=>"published",
    use 'post_status'=>"publish",

  3. technguide
    Member
    Posted 1 year ago #

    Ah shit. How did i overlook that. Thank you very much!!

Topic Closed

This topic has been closed to new replies.

About this Topic