Support » Fixing WordPress » Finding out post ID of NOT current page

  • Resolved timboreader

    (@timboreader)


    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

Viewing 2 replies - 1 through 2 (of 2 total)
  • <?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().
    ?>

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

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Finding out post ID of NOT current page’ is closed to new replies.