WP_Query::parse_query()
Parses a query string and sets query type booleans.
Method of the class: WP_Query{}
Hooks from the method
Return
null
. Nothing (null).
Usage
global $wp_query; $wp_query->parse_query( $query );
- $query(string|array)
Array or string of Query parameters.
Default: ''
-
attachment_id(int)
Attachment post ID. Used for 'attachment' post_type. -
author(int|string)
Author ID, or comma-separated list of IDs. -
author_name(string)
User 'user_nicename'. -
author__in(int[])
An array of author IDs to query from. -
author__not_in(int[])
An array of author IDs not to query from. -
cache_results(true|false)
Whether to cache post information.
Default: true -
cat(int|string)
Category ID or comma-separated list of IDs (this or any children). -
category__and(int[])
An array of category IDs (AND in). -
category__in(int[])
An array of category IDs (OR in, no children). -
category__not_in(int[])
An array of category IDs (NOT in). -
category_name(string)
Use category slug (not name, this or any children). -
comment_count(array|int)
Filter results by comment count. Provide an integer to match comment count exactly. Provide an array with integer 'value' and 'compare' operator ('=', '!=', '>', '>=', '<', '<=' ) to compare against comment_count in a specific way. -
comment_status(string)
Comment status. -
comments_per_page(int)
The number of comments to return per page. option.
Default: 'comments_per_page' -
date_query(array)
An associative array of WP_Date_Query arguments. See WP_Date_Query::__construct(). -
day(int)
Day of the month. Accepts numbers 1-31.
Default: '' -
exact(true|false)
Whether to search by exact keyword.
Default: false -
fields(string)
Post fields to query for. Accepts:- '' Returns an array of complete post objects (WP_Post[]).
- 'ids' Returns an array of post IDs (int[]).
- 'id=>parent' Returns an associative array of parent post IDs, keyed by post ID (int[]).
Default: ''
-
hour(int)
Hour of the day. Accepts numbers 0-23.
Default: '' -
ignore_sticky_posts(int|true|false)
Whether to ignore sticky posts or not. Setting this to false excludes stickies from 'post__in'. Accepts 1|true, 0|false.
Default: false -
m(int)
Combination YearMonth. Accepts any four-digit year and month numbers 01-12.
Default: '' -
meta_key(string|string[])
Meta key or keys to filter by. -
meta_value(string|string[])
Meta value or values to filter by. -
meta_compare(string)
MySQL operator used for comparing the meta value. See WP_Meta_Query::__construct() for accepted values and default value. -
meta_compare_key(string)
MySQL operator used for comparing the meta key. See WP_Meta_Query::__construct() for accepted values and default value. -
meta_type(string)
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_key(string)
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_query(array)
An associative array of WP_Meta_Query arguments. See WP_Meta_Query::__construct() for accepted values. -
menu_order(int)
The menu order of the posts. -
minute(int)
Minute of the hour. Accepts numbers 0-59.
Default: '' -
monthnum(int)
The two-digit month. Accepts numbers 1-12.
Default: '' -
name(string)
Post slug. -
nopaging(true|false)
Show all posts (true) or paginate (false).
Default: false -
no_found_rows(true|false)
Whether to skip counting the total rows found. Enabling can improve performance.
Default: false -
offset(int)
The number of posts to offset before retrieval. -
order(string)
Designates ascending or descending order of posts. Accepts 'ASC', 'DESC'.
Default: 'DESC' -
orderby(string|array)
Sort retrieved posts by parameter. One or more options may be passed. To use 'meta_value', or 'meta_value_num', 'meta_key=keyname' must be also be defined. To sort by a specific $meta_query clause, use that clause's array key. Accepts:- 'none'
- 'name'
- 'author'
- 'date'
- 'title'
- 'modified'
- 'menu_order'
- 'parent'
- 'ID'
- 'rand'
- 'relevance'
- 'RAND(x)' (where 'x' is an integer seed value)
- 'comment_count'
- 'meta_value'
- 'meta_value_num'
- 'post__in'
- 'post_name__in'
- 'post_parent__in'
- The array keys of $meta_query.
Default: 'date', except when a search is being performed, when the default is 'relevance'
-
p(int)
Post ID. -
page(int)
Show the number of posts that would show up on page X of a static front page. -
paged(int)
The number of the current page. -
page_id(int)
Page ID. -
pagename(string)
Page slug. -
perm(string)
Show posts if user has the appropriate capability. -
ping_status(string)
Ping status. -
post__in(int[])
An array of post IDs to retrieve, sticky posts will be included. -
post__not_in(int[])
An array of post IDs not to retrieve. Note: a string of comma- separated IDs will NOT work. -
post_mime_type(string)
The mime type of the post. Used for 'attachment' post_type. -
post_name__in(string[])
An array of post slugs that results must match. -
post_parent(int)
Page ID to retrieve child pages for. Use 0 to only retrieve top-level pages. -
post_parent__in(int[])
An array containing parent page IDs to query child pages from. -
post_parent__not_in(int[])
An array containing parent page IDs not to query child pages from. -
post_type(string|string[])
A post type slug (string) or array of post type slugs. if using 'tax_query'.
Default: 'any' -
post_status(string|string[])
A post status (string) or array of post statuses. -
posts_per_page(int)
The number of posts to query for. Use -1 to request all posts. -
posts_per_archive_page(int)
The number of posts to query for by archive page. Overrides 'posts_per_page' when is_archive(), or is_search() are true. -
s(string)
Search keyword(s). Prepending a term with a hyphen will exclude posts matching that term. Eg, 'pillow -sofa' will return posts containing 'pillow' but not 'sofa'. The character used for exclusion can be modified using the the 'wp_query_search_exclusion_prefix' filter. -
search_columns(string[])
Array of column names to be searched. Accepts 'post_title', 'post_excerpt' and 'post_content'.
Default: empty array -
second(int)
Second of the minute. Accepts numbers 0-59.
Default: '' -
sentence(true|false)
Whether to search by phrase.
Default: false -
suppress_filters(true|false)
Whether to suppress filters.
Default: false -
tag(string)
Tag slug. Comma-separated (either), Plus-separated (all). -
tag__and(int[])
An array of tag IDs (AND in). -
tag__in(int[])
An array of tag IDs (OR in). -
tag__not_in(int[])
An array of tag IDs (NOT in). -
tag_id(int)
Tag id or comma-separated list of IDs. -
tag_slug__and(string[])
An array of tag slugs (AND in). -
tag_slug__in(string[])
An array of tag slugs (OR in). unless 'ignore_sticky_posts' is true. Note: a string of comma-separated IDs will NOT work. -
tax_query(array)
An associative array of WP_Tax_Query arguments. See WP_Tax_Query::__construct(). -
title(string)
Post title. -
update_post_meta_cache(true|false)
Whether to update the post meta cache.
Default: true -
update_post_term_cache(true|false)
Whether to update the post term cache.
Default: true -
update_menu_item_cache(true|false)
Whether to update the menu item cache.
Default: false -
lazy_load_term_meta(true|false)
Whether to lazy-load term meta. Setting to false will disable cache priming for term meta, so that each get_term_meta() call will hit the database.
Default: value of $update_post_term_cache -
w(int)
The week number of the year. Accepts numbers 0-53.
Default: '' - year(int)
The four-digit year. Accepts any four-digit year.
Default: ''
-
Changelog
Since 1.5.0 | Introduced. |
Since 4.2.0 | Introduced the ability to order by specific clauses of a $meta_query, by passing the clause's array key to $orderby. |
Since 4.4.0 | Introduced $post_name__in and $title parameters. $s was updated to support excluded search terms, by prepending a hyphen. |
Since 4.5.0 | Removed the $comments_popup parameter. Introduced the $comment_status and $ping_status parameters. Introduced RAND(x) syntax for $orderby, which allows an integer seed value to random sorts. |
Since 4.6.0 | Added 'post_name__in' support for $orderby. Introduced the $lazy_load_term_meta argument. |
Since 4.9.0 | Introduced the $comment_count parameter. |
Since 5.1.0 | Introduced the $meta_compare_key parameter. |
Since 5.3.0 | Introduced the $meta_type_key parameter. |
Since 6.1.0 | Introduced the $update_menu_item_cache parameter. |
Since 6.2.0 | Introduced the $search_columns parameter. |