Wordpress check if post ID exists


/ Published in: PHP
Save to your folder(s)

Thanks to Tom McFarlin for this.

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


Copy this code and paste it in your HTML
  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. ?>

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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.