Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

How to check if page id(SomeID) is actually published?

share|improve this question
add comment

3 Answers

up vote 2 down vote accepted

You can use 'publish' === get_post_status( $id ), where $id could be the current page ID retrieved via get_the_ID() or any other.

share|improve this answer
    
@kaiser It's not really explicit that it's the current page he wants to check. At least that's not how I interpreted the question. –  hampusn Sep 19 '12 at 17:03
    
You're right. I'll fix it. Just wanted to get it out of the review row - too short answers are flagged by the community user. –  kaiser Sep 19 '12 at 17:03
    
Yeah I've noticed that several times. It's annoying when people forget to add back-ticks around php tags. Cheers :) –  hampusn Sep 19 '12 at 17:05
add comment

You must retrieve the page via the function get_page.

Look for the post_status field in the returned object!

share|improve this answer
add comment

You can try this:

<?php
  $page_id = 20; // example id of your page 
  $page = get_page( $page_id );
  if ($page->post_status == 'publish') {
    // page is published

  }
?>
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.