WordPress [WP_Post] 对象介绍

WordPress中的WP_Post(Post)对象是指文章对象,它是WordPress中最基本的内容类型之一。每篇文章都是一个Post对象,包含了文章的标题、内容、发布时间、作者、分类、标签等信息。Post对象是WordPress中最常用的对象之一,它可以通过WordPress提供的API进行创建、修改、删除、查询等操作。

Post对象包含以下属性:

  1. ID:文章的唯一标识符。
  2. post_author:文章的作者。
  3. post_date:文章的发布时间。
  4. post_content:文章的内容。
  5. post_title:文章的标题。
  6. post_excerpt:文章的摘要。
  7. post_status:文章的状态,如发布、草稿、待审核等。
  8. comment_status:文章的评论状态,如允许评论、禁止评论等。
  9. ping_status:文章的Ping状态,如允许Ping、禁止Ping等。
  10. post_password:文章的密码。
  11. post_name:文章的URL别名。
  12. post_modified:文章的修改时间。
  13. post_type:文章的类型,如文章、页面、自定义类型等。
  14. post_parent:文章的父级文章。
  15. post_mime_type:文章的媒体类型。

通过Post对象,我们可以对WordPress中的文章进行各种操作,如创建、修改、删除、查询等。同时,Post对象也是WordPress主题开发中最常用的对象之一,我们可以通过Post对象获取文章的各种信息,如标题、内容、发布时间、作者、分类、标签等,从而实现主题的定制化开发。

代码示例:

$post = get_post( 1 );
var_dump($post);
//结果
class WP_Post#5005 (24) {
  public $ID =>
  int(1)
  public $post_author =>
  string(1) "1"
  public $post_date =>
  string(19) "2023-04-12 09:39:59"
  public $post_date_gmt =>
  string(19) "2023-04-12 01:39:59"
  public $post_content =>
  string(151) "欢迎使用WordPress。这是您的第一篇文章。编辑或删除它,然后开始写作吧!"
  public $post_title =>
  string(18) "世界,您好!"
  public $post_excerpt =>
  string(0) ""
  public $post_status =>
  string(5) "trash"
  public $comment_status =>
  string(4) "open"
  public $ping_status =>
  string(4) "open"
  public $post_password =>
  string(0) ""
  public $post_name =>
  string(20) "hello-world__trashed"
  public $to_ping =>
  string(0) ""
  public $pinged =>
  string(0) ""
  public $post_modified =>
  string(19) "2023-04-12 09:46:04"
  public $post_modified_gmt =>
  string(19) "2023-04-12 01:46:04"
  public $post_content_filtered =>
  string(0) ""
  public $post_parent =>
  int(0)
  public $guid =>
  string(26) "http://localhost/rtdq/?p=1"
  public $menu_order =>
  int(0)
  public $post_type =>
  string(4) "post"
  public $post_mime_type =>
  string(0) ""
  public $comment_count =>
  string(1) "1"
  public $filter =>
  string(3) "raw"
}
发布日期:2023-04-12 浏览次数:630

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注