Posted By

adambundy on 07/30/14


Tagged

wordpress


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

adambundy


Wordpress check if post ID exists


 / Published in: PHP
 

URL: http://tommcfarlin.com/wordpress-post-exists-by-id/#more-30264

Thanks to Tom McFarlin for this.

http://tommcfarlin.com/wordpress-post-exists-by-id/#more-30264

  1. <?php
  2.  
  3. /**
  4.  * Determines if a post, identified by the specified ID, exist
  5.  * within the WordPress database.
  6.  *
  7.  * Note that this function uses the 'acme_' prefix to serve as an
  8.  * example for how to use the function within a theme. If this were
  9.  * to be within a class, then the prefix would not be necessary.
  10.  *
  11.  * @param int $id The ID of the post to check
  12.  * @return bool True if the post exists; otherwise, false.
  13.  * @since 1.0.0
  14.  */
  15. function acme_post_exists( $id ) {
  16. return is_string( get_post_status( $id ) );
  17. }
  18. ?>

Report this snippet  

You need to login to post a comment.