WordPress.org

Ready to get started?Download WordPress

Forums

Checking if a specific post is a draft? after wp_get_recent_posts(); (4 posts)

  1. saiberfun
    Member
    Posted 4 years ago #

    Hello,
    What I'm doing is checking for the latest post(s)
    I use
    $recent_posts = wp_get_recent_posts();

    to get the recent posts and then

    foreach( $recent_posts as $post ){
    				$wpname = $post["post_title"];
    				$wplink = get_permalink( $post["ID"] );
    				echo '
    				[WP_CFG]<br>
    				wppname="'.$wpname.'"
    				wpplink="'.$wplink.'"
    				wppactive="1"';
    				break;
    			}

    to output the latest post
    but I need to check if the post is a draft or not
    so if it is it will continue to the next post...

    But I don't know if and if yes how to check if a post is for draft or not.

    So can you check for this and if yes how?

  2. saiberfun
    Member
    Posted 4 years ago #

    sry to bump I know its against the rules and stuff
    but after 1 day, almost 2 days noone even tried to help :/

    guys really this is important....

    sry again mods
    but I can't believe that anyone looking to help someone now will ever find this thread even by looking for the 'no reply' threads...

  3. MaFt
    Member
    Posted 3 years ago #

    if($post['post_status'] == "publish"){ //do something }
    
    else { // it's not published (i.e. draft or other) so do nothing }

    hope that helps?

    if in doubt simply do a print_r($post) and it will show the full array with keys and values.

    that's how i found the 'post_status' key

    MaFt

  4. Escort-Italia
    Member
    Posted 3 years ago #

    using

    if($post->post_status  == "publish"){ //do something }
    
    else { // it's not published (i.e. draft or other) so do nothing }

Topic Closed

This topic has been closed to new replies.

About this Topic