WordPress [WP_Post] 对象介绍
WordPress中的WP_Post(Post)对象是指文章对象,它是WordPress中最基本的内容类型之一。每篇文章都是一个Post对象,包含了文章的标题、内容、发布时间、作者、分类、标签等信息。Post对象是WordPress中最常用的对象之一,它可以通过WordPress提供的API进行创建、修改、删除、查询等操作。
Post对象包含以下属性:
- ID:文章的唯一标识符。
- post_author:文章的作者。
- post_date:文章的发布时间。
- post_content:文章的内容。
- post_title:文章的标题。
- post_excerpt:文章的摘要。
- post_status:文章的状态,如发布、草稿、待审核等。
- comment_status:文章的评论状态,如允许评论、禁止评论等。
- ping_status:文章的Ping状态,如允许Ping、禁止Ping等。
- post_password:文章的密码。
- post_name:文章的URL别名。
- post_modified:文章的修改时间。
- post_type:文章的类型,如文章、页面、自定义类型等。
- post_parent:文章的父级文章。
- 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"
}
发表回复