WordPress 函数:get_comments 评论查询 参数大全

追格官方小助手/ 2023年01月14日/ WordPress/ 浏览 1300

在 WordPress 中,get_comments 负责评论查询,其功能强大,参数负责,值得重点学习一下。


其参数如下:


author_email string


作者电子邮件地址


author_url string


作者URL


author__in int[]


作者ID数组


author__not_in int[]


需要排除的作者ID数组


comment__in int[]


评论ID数组


comment__not_in int[]


需要排除的评论ID数组


count bool


true 则只返回数量,默认false


fields string


Comment fields to return. Accepts 'ids' for comment IDs only or empty for all fields.

只接受 'ids' 或 '','ids'只返回ID,''返回所有字段


include_unapproved array


评论ID数组 或 用户email数组,未批准的评论也会返回


karma int


Karma score to retrieve matching comments for.(这说的是啥?)


meta_key string|string[]


附加属性键。


meta_value string|string[]


附加属性值。


meta_compare string


附加属性比较符号。支持MySQL操作符。参考:WP_Meta_Query::__construct()。


meta_compare_key string


附加属性的key,支持MySQL关键字,参考:See WP_Meta_Query::__construct() 。


meta_type string


附加属性的值类型,参考:WP_Meta_Query::__construct()。


meta_type_key string


附加属性的值类型的key,参考:WP_Meta_Query::__construct()。


meta_query array


附加属性查询数组,参考:WP_Meta_Query::__construct()。


number int


数量限制。默认无限制。


paged int


与$number一起使用时,定义要返回的结果页。与$offset一起使用时,$offset优先。默认值1。


offset int


要偏移查询的评论数。用于生成LIMIT子句。默认值为0。


no_found_rows bool


是否禁用SQL_CALC_FOUND_ROWS查询。默认值:true。


orderby string|array


评论状态或状态数组。要使用“meta_value”或“meta_vvalue_num”,还必须定义$meta_key。要按特定的$meta_query子句排序,请使用该子句的数组键。接受:


'comment_agent'

'comment_approved'

'comment_author'

'comment_author_email'

'comment_author_IP'

'comment_author_url'

'comment_content'

'comment_date'

'comment_date_gmt'

'comment_ID'

'comment_karma'

'comment_parent'

'comment_post_ID'

'comment_type'

'user_id'

'comment__in'

'meta_value'

'meta_value_num'

The value of $meta_key

The array keys of $meta_query

false, an empty array, or 'none' to disable ORDER BY clause.

Default: 'comment_date_gmt'.


order string


如何排序检索到的评论。接受“ASC”、“DESC”。默认值:“DESC”。


parent int


要检索其子级的评论的父ID。


parent__in int[]


要检索其子级的评论的父ID数组。


parent__not_in int[]


要为其检索子级的评论*而非*的父ID数组。


post_author__in int[]


要为其检索评论的作者ID数组。


post_author__not_in int[]


要检索其评论的作者ID数组*不*。


post_id int


将结果限制为与给定帖子ID关联的结果。默认值为0。


post__in int[]


包含附属评论的帖子ID数组。


post__not_in int[]


要排除其关联评论的帖子ID数组。


post_author int


发布作者ID以限制结果。


post_status string|string[]


要检索其关联评论的帖子状态或帖子状态数组。传递“any”以匹配任何值。


post_type string|string[]


要检索其附属评论的文章类型或文章类型数组。传递“any”以匹配任何值。


post_name string


要检索其关联评论的帖子名称。


post_parent int


发布父ID以检索其附属评论。


search string


要检索其匹配评论的搜索项。


status string|array


限制结果的评论状态。接受“保持”(Comment_status=0)、“批准”(Comment _status=1)、“全部”或自定义评论状态的数组或空格/逗号分隔列表。默认为“all”。


type string|string[]


包括给定类型或类型数组的评论。


接受“comment”、“ping”(包括“pingback”和“trackback”)或任何自定义类型字符串。


type__in string[]


包括来自给定评论类型数组的评论。


type__not_in string[]


从给定的评论类型数组中排除评论。


user_id int


包括特定用户ID的评论。


hierarchical bool|string


是否在结果中包含评论子体。“thread”返回一个树,每个评论的子级存储在WP_comment对象的children属性中。“flat”返回找到的评论及其子项的平面数组。布尔值为false时会忽略后代。当$fields为“ids”或“counts”时,将忽略该参数(强制为false)。接受“thread”、“flat”或false。默认值:false。


cache_domain string


将此查询存储在对象缓存中时要生成的唯一缓存键。默认值为“core”。


update_comment_meta_cache布尔值


是否为找到的评论填充元数据缓存。默认为true。


update_comment_post_cache bool


是否为评论文章填充缓存。默认值为false。


发表评论

暂无评论,抢个沙发...

客服 工单