Wordpress检查post ID是否存在

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Wordpress检查post ID是否存在相关的知识,希望对你有一定的参考价值。

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. ?>

以上是关于Wordpress检查post ID是否存在的主要内容,如果未能解决你的问题,请参考以下文章