Constructor.
Sets up the comment query, based on the query vars passed.
$querystring|arrayoptional
author_email stringauthor_url stringauthor__in int[]author__not_in int[]comment__in int[]comment__not_in int[]count booldate_query arrayfields string'ids' for comment IDs only or empty for all fields. include_unapproved array$status. karma intmeta_key string|string[]meta_value string|string[]meta_compare stringmeta_compare_key stringmeta_type stringmeta_type_key stringmeta_query arraynumber intpaged int$number, defines the page of results to return.$offset, $offset takes precedence. Default 1.offset intno_found_rows boolSQL_CALC_FOUND_ROWS query.orderby string|array'meta_value' or 'meta_value_num', $meta_key must also be defined.$meta_query clause, use that clause’s array key. Accepts:'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'$meta_key
$meta_query
'none' to disable ORDER BY clause.'comment_date_gmt'.order string'ASC', 'DESC'.'DESC'.parent intparent__in int[]parent__not_in int[]post_author__in int[]post_author__not_in int[]post_id intpost__in int[]post__not_in int[]post_author intpost_status string|string[]'any' to match any value.post_type string|string[]'any' to match any value. post_name stringpost_parent intsearch stringstatus string|array'hold' (comment_status=0), 'approve' (comment_status=1), 'all', or a custom comment status. Default 'all'.type string|string[]'comment', 'pings' (includes 'pingback' and 'trackback'), or any custom type string. type__in string[]type__not_in string[]user_id inthierarchical bool|string'threaded' returns a tree, with each comment’s children stored in a children property on the WP_Comment object.'flat' returns a flat array of found comments plus their children.false leaves out descendants.false) when $fields is 'ids' or 'counts'. Accepts 'threaded', 'flat', or false. Default: false.cache_domain string'core'.update_comment_meta_cache boolupdate_comment_post_cache boolDefault:''
public function __construct( $query = '' ) {
$this->query_var_defaults = array(
'author_email' => '',
'author_url' => '',
'author__in' => '',
'author__not_in' => '',
'include_unapproved' => '',
'fields' => '',
'ID' => '',
'comment__in' => '',
'comment__not_in' => '',
'karma' => '',
'number' => '',
'offset' => '',
'no_found_rows' => true,
'orderby' => '',
'order' => 'DESC',
'paged' => 1,
'parent' => '',
'parent__in' => '',
'parent__not_in' => '',
'post_author__in' => '',
'post_author__not_in' => '',
'post_ID' => '',
'post_id' => 0,
'post__in' => '',
'post__not_in' => '',
'post_author' => '',
'post_name' => '',
'post_parent' => '',
'post_status' => '',
'post_type' => '',
'status' => 'all',
'type' => '',
'type__in' => '',
'type__not_in' => '',
'user_id' => '',
'search' => '',
'count' => false,
'meta_key' => '',
'meta_value' => '',
'meta_query' => '',
'date_query' => null, // See WP_Date_Query.
'hierarchical' => false,
'cache_domain' => 'core',
'update_comment_meta_cache' => true,
'update_comment_post_cache' => false,
);
if ( ! empty( $query ) ) {
$this->query( $query );
}
}
| Version | Description |
|---|---|
| 5.3.0 | Introduced the $meta_type_key argument. |
| 5.1.0 | Introduced the $meta_compare_key argument. |
| 4.9.0 | Introduced the $paged argument. |
| 4.6.0 | Introduced the $cache_domain argument. |
| 4.5.0 | Introduced the $author_url argument. |
| 4.4.0 | Order by comment__in was added. $update_comment_meta_cache, $no_found_rows, $hierarchical, and $update_comment_post_cache were added. |
| 4.2.0 | Introduced. |
© 2003–2024 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/classes/wp_comment_query/__construct