get_comments()获取所有的评论(可筛选)

目录

描述

Retrieve a list of comments.

get_comments() 描述

用法

<?php get_comments$args ); ?>

Default Usage

get_comments() 用法

参数

$author_email

(string) (可选) Comment author email address.

默认值: empty

$author__in

(array) (可选) Array of author IDs to include comments for.

默认值: empty

$author__not_in

(array) (可选) Array of author IDs to exclude comments for.

默认值: empty

$comment__in

(array) (可选) Array of comment IDs to include.

默认值: empty

$comment__not_in

(array) (可选) Array of comment IDs to exclude.

默认值: empty

$count

(bool) (可选) Whether to return a comment count (true) or array of comment objects (false).

默认值: false

$date_query

(array) (可选) Date query clauses to limit comments by. See WP_Date_Query.

默认值: null

$fields

(string) (可选) Comment fields to return. Accepts 'ids' for comment IDs only or empty for all fields.

默认值: empty

$ID

(int) (可选) Currently unused.

默认值: None

$include_unapproved

(array) (可选) Array of IDs or email addresses of users whose unapproved comments will be returned by the query regardless of $status.

默认值: empty

$karma

(int) (可选) Karma score to retrieve matching comments for.

默认值: empty

$meta_key

(string) (可选) Include comments with a matching comment meta key.

默认值: empty

$meta_value

(string) (可选) Include comments with a matching comment meta value. Requires $meta_key to be set.

默认值: empty

$meta_query

(array) (可选) Meta query clauses to limit retrieved comments by. See WP_Meta_Query.

默认值: empty

$number

(int) (可选) Maximum number of comments to retrieve.

默认值: null (no limit)

$offset

(int) (0) Number of comments to offset the query. Used to build LIMIT clause.

默认值: None

$orderby

(string_array) (可选) Comment status or array of statuses. To use 'meta_value' or 'meta_value_num', $meta_key must also be defined. To sort by a specific $meta_query clause, use that clause's array key.

  • 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
  • meta_value
  • meta_value_num
  • the value of $meta_key
  • and the array keys of $meta_query
  • Also accepts false, an empty array, or 'none' to disable ORDER BY clause
  • 默认值: comment_date_gmt

$order

(string) (可选) How to order retrieved comments. Accepts

  • ASC
  • DESC
  • .

    默认值: 'DESC'.

$parent

(int) (可选) Parent ID of comment to retrieve children of.

默认值: empty

$post_author__in

(array) (可选) Array of author IDs to retrieve comments for.

默认值: empty

$post_author__not_in

(array) (可选) Array of author IDs *not* to retrieve comments for.

默认值: empty

$post_ID

(int) (可选) Currently unused

默认值: None

$post_id

(int) (可选) Limit results to those affiliated with a given post ID.

默认值: 0

$post__in

(array) (可选) Array of post IDs to include affiliated comments for.

默认值: empty

$post__not_in

(array) (可选) Array of post IDs to exclude affiliated comments for.

默认值: empty

$post_author

(int) (可选) Comment author ID to limit results by.

默认值: empty

$post_status

(string) (可选) Post status to retrieve affiliated comments for.

默认值: empty

$post_type

(string) (可选) Post type to retrieve affiliated comments for.

默认值: empty

$post_name

(string) (可选) Post name to retrieve affiliated comments for.

默认值: empty

$post_parent

(int) (可选) Post parent ID to retrieve affiliated comments for.

默认值: empty

$search

(string) (可选) Search term(s) to retrieve matching comments for.

默认值: empty

$status

(string) ('all') optional

默认值: None

$type

(string_array) (可选) Include comments of a given type, or array of types. Accepts 'comment', 'pings' (includes 'pingback' and 'trackback'), or any custom type string.

默认值: empty

$type__in

(array) (可选) Include comments from a given array of comment types.

默认值: empty

$type__not_in

(array) (可选) Exclude comments from a given array of comment types.

默认值: empty

$user_id

(int) (可选) Include comments for a specific user ID.

默认值: empty

get_comments() 参数

示例

Show last 5 unapproved comments:

Show comment counts of a post:

Show comment counts of a user:

Show comments of a user:

Get comments from last 4 weeks:

Delete duplicate comments (same author and content):

get_comments() 示例

源文件

get_comments() 函数的代码位于 wp-includes/comment.php.

get_comments() 源文件

相关