WP_发布{}

用于实现WP_支柱对象。

更多信息

WP_Post的角色

这个WP_支柱类用于包含数据库存储的post对象,并由以下函数返回获取_发布.

方法

姓名描述
WP_发布::__construct建造师。
WP_发布::__get盖特。
WP_发布::__issetIsset-er公司。
WP_Post::过滤器{@缺少摘要}
WP_发布::获取实例检索WP_支柱实例。
WP_发布::到阵列(_A)将对象转换为数组。

来源

最后一堂课WP_Post{/***帖子ID。**@自3.5.0起*@var整数*/公共$ID;/***帖子作者的ID。**出于兼容性原因,为数字字符串。**@自3.5.0起*@var字符串*/public$post_author=0;/***该帖子的本地发布时间。**@自3.5.0起*@var字符串*/public$post_date=“0000-00-00 00:00:00”;/***文章的GMT发布时间。**@自3.5.0起*@var字符串*/public$post_date_gmt=“0000-00-00 00:00:00”;/***帖子的内容。**@自3.5.0起*@var字符串*/public$post_content='';/***帖子的标题。**@自3.5.0起*@var字符串*/public$post_title=“”;/***这篇文章的摘录。**@自3.5.0起*@var字符串*/public$post_excerpt=“”;/***帖子的状态。**@自3.5.0起*@var字符串*/public$post_status='publish';/***是否允许评论。**@自3.5.0起*@var字符串*/public$comment_status=“打开”;/***是否允许ping。**@自3.5.0起*@var字符串*/public$ping_status=“打开”;/***明文形式的帖子密码。**@自3.5.0起*@var字符串*/public$post_password=“”;/***这根柱子上的子弹。**@自3.5.0起*@var字符串*/公共$post_name=“”;/***排队等待ping的URL。**@自3.5.0起*@var字符串*/public$to_ping=“”;/***已Ping的URL。**@自3.5.0起*@var字符串*/public$pinged=“”;/***帖子的本地修改时间。**@自3.5.0起*@var字符串*/public$post_modified=“0000-00-00 00:00:00”;/***帖子的GMT修改时间。**@自3.5.0起*@var字符串*/public$post_modified_gmt=“0000-00-00 00:00:00”;/***用于发布内容的实用数据库字段。**@自3.5.0起*@var字符串*/public$post_content_filtered=“”;/***帖子的父帖子的ID。**@自3.5.0起*@var整数*/公共$post_parent=0;/***文章的唯一标识符,不一定是URL,用作提要GUID。**@自3.5.0起*@var字符串*/公共$guid=“”;/***用于排序帖子的字段。**@自3.5.0起*@var整数*/公共$menu_order=0;/***帖子的类型,如帖子或页面。**@自3.5.0起*@var字符串*/public$post_type='post';/***附件的mime类型。**@自3.5.0起*@var字符串*/公共$post_time_type=“”;/***缓存的注释计数。**出于兼容性原因,为数字字符串。**@自3.5.0起*@var字符串*/public$comment_count=0;/***存储post对象的清理级别。**与数据库字段不对应。**@自3.5.0起*@var字符串*/公共$filter;/***检索WP_Post实例。**@自3.5.0起**@global wpdb$wpdb WordPress数据库抽象对象。**@param int$post_id帖子id。*@return WP_Post | false Post对象,否则为false。*/公共静态函数getinstance($post_id){全局$wpdb;$post_id=(int)$post_id;if(!$post_id){返回false;}$_post=wp_cache_get($post_id,'posts');if(!$_post){$_post=$wpdb->get_row($wpdb->prepare(“SELECT*FROM$wpdb->posts WHERE ID=%d LIMIT 1”,$post_ID);if(!$_post){返回false;}$_post=消毒post($_post,'raw');wp_cache_add($_post->ID,$_post,'帖子');}elseif(空($_post->filter)||“原始”!==$_后->过滤器){$_post=消毒post($_post,'raw');}返回新的WP_Post($_Post);}/***建造师。**@自3.5.0起**@param WP_Post | object$Post Post对象。*/公共函数__construct($post){foreach(getobject_vars($post)作为$key=>$value){$this->$key=$value;}}/***Isset-er公司。**@自3.5.0起**@param string$key要检查是否已设置的属性。*@return布尔*/公共函数__isset($key){if(“祖先”===$key){返回true;}if(“page_template”===$key){返回true;}if(“post_category”===$key){返回true;}if('tags_input'===$key){返回true;}return metadata_exists('post',$this->ID,$key);}/***格特。**@自3.5.0起**@param string$key要获取的密钥。*@返回混合*/公共函数__get($key){if(“page_template”===$key&&$this->__isset($key)){return get_post_meta($this->ID,'_wp_page_template',true);}if(“post_category”===$key){if(isobjectin_taxonomy($this->posttype,'category')){$terms=get_the_terms($this,“类别”);}if(空($terms)){返回数组();}return wp_list_pluck($terms,'term_id');}if('tags_input'===$key){if(is_object_in_taxonomy($this->post_type,'post_tag')){$terms=get_the_terms($this,'post_tag');}if(空($terms)){返回数组();}return wp_list_pluck($terms,'name');}//其余值需要过滤。if(“祖先”===$key){$value=get_post_ancestors($this);}其他{$value=get_post_meta($this->ID,$key,true);}if($this->过滤器){$value=清理post_field($key,$value,$this->ID,$this->filter);}返回$value;}/***{@缺少摘要}**@自3.5.0起**@param string$filter过滤器。*@return WP_Post*/公共函数过滤器($filter){if($this->filter===$filter){返回$this;}if(“原始”===$filter){return self::get_instance($this->ID);}return sanitize_post($this,$filter);}/***将对象转换为数组。**@自3.5.0起**@return array对象作为数组。*/公共函数to_array(){$post=获取对象变量($this);foreach(数组(“祖先”、“page_template”、“post_category”、“tags_input”)作为$key){if($this->__isset($key)){$post[$key]=$this->__get($key);}}返回$post;}}

变更日志

版本描述
3.5.0介绍。

用户贡献的笔记

  1. 跳到注释4内容

    请注意: 虽然上述方法可以检索帖子ID,但不应使用上述方法显示post_content和其他过滤元素(例如post_title)。如果在循环中,则应该使用_content,如果在循环外,则应使用apply_filters,这样看起来像这样

    $examplePost=get_post();echo$examplePost->post_content;//不要这样做echo apply_filters('the_content',$examplePost->post_content);//改为这样做
  2. 跳到注释6内容

    我找到了一个更长的成员变量列表WP_支柱对象,至少对于菜单项WP_支柱对象和WordPress v5.5.1。其他变量包括:

    成员变量变量类型

    to_ping字符串
    ping字符串
    post_content_filtered字符串
    guid字符串
    post_time_type字符串
    过滤器字符串
    db_id整数
    menu_item_parent字符串
    object_id字符串
    对象字符串
    键入字符串
    type_label字符串
    url字符串
    标题字符串

你必须登录在能够发表注释或反馈之前。