WP_Comment_Query::parse_query( string|array $query = '' )

Parse arguments passed to the comment query with default query parameters.


Parameters

$query string|array Optional
WP_Comment_Query arguments. See WP_Comment_Query::__construct()
More Arguments from WP_Comment_Query::__construct( ... $query ) Array or query string of comment query parameters.
  • author_emailstring
    Comment author email address.
  • author_urlstring
    Comment author URL.
  • author__inint[]
    Array of author IDs to include comments for.
  • author__not_inint[]
    Array of author IDs to exclude comments for.
  • comment__inint[]
    Array of comment IDs to include.
  • comment__not_inint[]
    Array of comment IDs to exclude.
  • countbool
    Whether to return a comment count (true) or array of comment objects (false). Default false.
  • date_queryarray
    Date query clauses to limit comments by. See WP_Date_Query.
    Default null.
  • fieldsstring
    Comment fields to return. Accepts 'ids' for comment IDs only or empty for all fields.
  • IDint
    Currently unused.
  • include_unapprovedarray
    Array of IDs or email addresses of users whose unapproved comments will be returned by the query regardless of $status.
  • karmaint
    Karma score to retrieve matching comments for.
  • meta_keystring|string[]
    Meta key or keys to filter by.
  • meta_valuestring|string[]
    Meta value or values to filter by.
  • meta_comparestring
    MySQL operator used for comparing the meta value.
    See WP_Meta_Query::__construct() for accepted values and default value.
  • meta_compare_keystring
    MySQL operator used for comparing the meta key.
    See WP_Meta_Query::__construct() for accepted values and default value.
  • meta_typestring
    MySQL data type that the meta_value column will be CAST to for comparisons.
    See WP_Meta_Query::__construct() for accepted values and default value.
  • meta_type_keystring
    MySQL data type that the meta_key column will be CAST to for comparisons.
    See WP_Meta_Query::__construct() for accepted values and default value.
  • meta_queryarray
    An associative array of WP_Meta_Query arguments.
    See WP_Meta_Query::__construct() for accepted values.
  • numberint
    Maximum number of comments to retrieve.
    Default empty (no limit).
  • pagedint
    When used with $number, defines the page of results to return.
    When used with $offset, $offset takes precedence. Default 1.
  • offsetint
    Number of comments to offset the query. Used to build LIMIT clause. Default 0.
  • no_found_rowsbool
    Whether to disable the SQL_CALC_FOUND_ROWS query.
    Default: true.
  • orderbystring|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. 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'
    • 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'.
  • orderstring
    How to order retrieved comments. Accepts 'ASC', 'DESC'.
    Default: 'DESC'.
  • parentint
    Parent ID of comment to retrieve children of.
  • parent__inint[]
    Array of parent IDs of comments to retrieve children for.
  • parent__not_inint[]
    Array of parent IDs of comments *not* to retrieve children for.
  • post_author__inint[]
    Array of author IDs to retrieve comments for.
  • post_author__not_inint[]
    Array of author IDs *not* to retrieve comments for.
  • post_IDint
    Currently unused.
  • post_idint
    Limit results to those affiliated with a given post ID.
    Default 0.
  • post__inint[]
    Array of post IDs to include affiliated comments for.
  • post__not_inint[]
    Array of post IDs to exclude affiliated comments for.
  • post_authorint
    Post author ID to limit results by.
  • post_statusstring|string[]
    Post status or array of post statuses to retrieve affiliated comments for. Pass 'any' to match any value.
  • post_typestring|string[]
    Post type or array of post types to retrieve affiliated comments for. Pass 'any' to match any value.
  • post_namestring
    Post name to retrieve affiliated comments for.
  • post_parentint
    Post parent ID to retrieve affiliated comments for.
  • searchstring
    Search term(s) to retrieve matching comments for.
  • statusstring|array
    Comment statuses to limit results by. Accepts an array or space/comma-separated list of 'hold' (comment_status=0), 'approve' (comment_status=1), 'all', or a custom comment status. Default 'all'.
  • typestring|string[]
    Include comments of a given type, or array of types.
    Accepts 'comment', 'pings' (includes 'pingback' and 'trackback'), or any custom type string.
  • type__instring[]
    Include comments from a given array of comment types.
  • type__not_instring[]
    Exclude comments from a given array of comment types.
  • user_idint
    Include comments for a specific user ID.
  • hierarchicalbool|string
    Whether to include comment descendants in the results.
    • '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.
    • Boolean false leaves out descendants.
    The parameter is ignored (forced to false) when $fields is 'ids' or 'counts'. Accepts 'threaded', 'flat', or false. Default: false.
  • cache_domainstring
    Unique cache key to be produced when this query is stored in an object cache. Default is 'core'.
  • update_comment_meta_cachebool
    Whether to prime the metadata cache for found comments.
    Default true.
  • update_comment_post_cachebool
    Whether to prime the cache for comment posts.
    Default false.

Default: ''


Top ↑

Source

File: wp-includes/class-wp-comment-query.php. View all references

public function parse_query( $query = '' ) {
	if ( empty( $query ) ) {
		$query = $this->query_vars;
	}

	$this->query_vars = wp_parse_args( $query, $this->query_var_defaults );

	/**
	 * Fires after the comment query vars have been parsed.
	 *
	 * @since 4.2.0
	 *
	 * @param WP_Comment_Query $query The WP_Comment_Query instance (passed by reference).
	 */
	do_action_ref_array( 'parse_comment_query', array( &$this ) );
}

Top ↑

Hooks



Top ↑

Changelog

Changelog
Version Description
4.2.0 Introduced.

Top ↑

User Contributed Notes

You must log in before being able to contribute a note or feedback.