Posted By

adambundy on 07/30/14


Tagged

wordpress


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

adambundy
tryan326


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  

Comments

RSS Icon Subscribe to comments
Posted By: robertfcrocker on September 14, 2017

This type of message always inspiring and I prefer to read quality content, so happy to find good place to many here in the post, the writing is just great, thanks for the post. official website

You need to login to post a comment.