WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Finding out post ID of NOT current page (3 posts)

  1. timboreader
    Member
    Posted 4 years ago #

    Hi,
    I need to find out the post ID for a page *which isn't the current page* and in such a way that I can then find the page's post_status (eg 'publish', 'draft').

    This is so that I can output a notification on the home page depending on whether e.g. the contact page is live or not.

    e.g.
    IF contact_page_form == 'publish' THEN
    display notification
    END IF

    Thanks

    Tim

  2. MichaelH
    Member
    Posted 4 years ago #

    <?php
    $args=array(
      'name' => 'About',
      'post_type' => 'page',
      'post_status' => 'any',
      'posts_per_page' => 1,
      'caller_get_posts'=> 1
    );
    $my_query = null;
    $my_query = new WP_Query($args);
    if( $my_query->have_posts() ) {
      if ($my_query->posts[0]->post_status == 'publish' ) {
        echo 'we are good to go!';
      }
    }
    wp_reset_query();  // Restore global post data stomped by the_post().
    ?>
  3. timboreader
    Member
    Posted 4 years ago #

    Thanks MichaelH, that's just what I was after.
    Tim

Topic Closed

This topic has been closed to new replies.

About this Topic