CC Software / wp-query-cheat-sheet

WP_Querycheat sheet

Every parameter you can pass to new WP_Query(), grouped by what it does, with a copyable example for each group.

Open the playgroundRun queries against a real WordPress in your browser

Inspired by wp-query-ref by luetkemj, the one-page WP_Query reference a generation of WordPress developers copied from. More about that

00

Basic usage

Build an array of arguments, pass it to WP_Query, loop over the results, then reset post data so template tags point back at the main query.

The Loop
$query = new WP_Query( array(
  'post_type'      => 'post',
  'posts_per_page' => 10,
) );

if ( $query->have_posts() ) :
  while ( $query->have_posts() ) : $query->the_post();
    the_title( '<h2>', '</h2>' );
  endwhile;
endif;

// Restore the main query's $post.
wp_reset_postdata();
$query = new WP_Query( [
  'post_type'      => 'post',
  'posts_per_page' => 10,
] );

if ( $query->have_posts() ) :
  while ( $query->have_posts() ) : $query->the_post();
    the_title( '<h2>', '</h2>' );
  endwhile;
endif;

// Restore the main query's $post.
wp_reset_postdata();
01

Author

Docs ↗

Show posts by, or not by, certain authors.

ParameterTypeDescription
authorintstringAuthor ID, or a comma-separated list of IDs. Prefix an ID with - to exclude it: '-1,-2'.
author_namestringThe author's user_nicename, not their display name.
author__in 3.7+int[]Posts by any of these author IDs.
author__not_in 3.7+int[]Posts by none of these author IDs.
Posts by two authorsTry it
$args = array(
  'author__in' => array( 2, 6 ),
);
$args = [
  'author__in' => [ 2, 6 ],
];
02

Category

Docs ↗

Show posts in, or not in, certain categories.

ParameterTypeDescription
catintstringCategory ID, children included. Comma-separate several IDs; prefix with - to exclude: '-12,-34'.
category_namestringCategory slug, children included. 'staff,news' matches any; 'staff+news' matches all.
category__andint[]Posts in all of these categories.
category__inint[]Posts in any of these categories. Children are not included.
category__not_inint[]Posts in none of these categories. Children are not included.
In news, but not in staffTry it
$args = array(
  'category__in'     => array( 2 ),
  'category__not_in' => array( 6 ),
);
$args = [
  'category__in'     => [ 2 ],
  'category__not_in' => [ 6 ],
];
03

Tag

Docs ↗

Show posts with, or without, certain tags.

ParameterTypeDescription
tagstringTag slug. 'bread,baking' matches any; 'bread+baking' matches all.
tag_idintTag ID.
tag__andint[]Posts with all of these tag IDs.
tag__inint[]Posts with any of these tag IDs.
tag__not_inint[]Posts with none of these tag IDs.
tag_slug__andstring[]Posts with all of these tag slugs.
tag_slug__instring[]Posts with any of these tag slugs.
Any of two tagsTry it
$args = array(
  'tag_slug__in' => array( 'red', 'blue' ),
);
$args = [
  'tag_slug__in' => [ 'red', 'blue' ],
];
04

Taxonomy

Docs ↗

Query any taxonomy, including custom ones, with boolean logic between clauses.

ParameterTypeDescription
tax_query 3.1+arrayAn array of clause arrays. Clauses can be nested, each with its own relation.

Keys inside tax_query

ParameterTypeDescription
relationstringHow clauses combine: 'AND' (default) or 'OR'. Goes in the outer array.
taxonomystringTaxonomy name. Optional when field is 'term_taxonomy_id'.
fieldstringWhat terms holds: 'term_id' (default), 'slug', 'name' or 'term_taxonomy_id'.
termsintstringarrayThe term or terms to match.
include_childrenboolInclude child terms of hierarchical taxonomies. Default true.
operatorstring'IN' (default), 'NOT IN', 'AND', 'EXISTS' or 'NOT EXISTS'.
Red or blue, but not in StaffTry it
$args = array(
  'tax_query' => array(
    'relation' => 'AND',
    array(
      'taxonomy' => 'color',
      'field'    => 'slug',
      'terms'    => array( 'red', 'blue' ),
    ),
    array(
      'taxonomy'         => 'category',
      'field'            => 'slug',
      'terms'            => array( 'staff' ),
      'include_children' => false,
      'operator'         => 'NOT IN',
    ),
  ),
);
$args = [
  'tax_query' => [
    'relation' => 'AND',
    [
      'taxonomy' => 'color',
      'field'    => 'slug',
      'terms'    => [ 'red', 'blue' ],
    ],
    [
      'taxonomy'         => 'category',
      'field'            => 'slug',
      'terms'            => [ 'staff' ],
      'include_children' => false,
      'operator'         => 'NOT IN',
    ],
  ],
];
05

Post & Page

Docs ↗

Fetch specific posts or pages by ID, slug, title or parent.

ParameterTypeDescription
pintPost ID.
namestringPost slug.
title 4.4+stringPost title, exact match.
page_idintPage ID.
pagenamestringPage slug. For a child page use 'parent/child'.
attachment_idintAttachment ID.
post_name__in 4.4+string[]Posts with any of these slugs.
post_parentintChildren of this ID. Use 0 for top-level entries only. Hierarchical post types only.
post_parent__in 3.6+int[]Posts whose parent is any of these IDs.
post_parent__not_in 3.6+int[]Posts whose parent is none of these IDs.
post__inint[]Only these post IDs. Sticky posts are still prepended unless ignore_sticky_posts is set.
post__not_inint[]Exclude these post IDs. Must be an array; a comma-separated string does not work.
menu_orderintPosts with exactly this menu order.
Specific posts, in the given orderTry it
$args = array(
  'post_name__in' => array( 'staff-picks-for-summer', 'hello-world', 'cooking-with-cast-iron' ),
  'orderby'       => 'post_name__in',
);
$args = [
  'post_name__in' => [ 'staff-picks-for-summer', 'hello-world', 'cooking-with-cast-iron' ],
  'orderby'       => 'post_name__in',
];
06

Password

Docs ↗

Filter by whether posts are password protected.

ParameterTypeDescription
has_password 3.9+boolnulltrue for posts with a password, false for posts without, null for both.
post_password 3.9+stringPosts with this exact password. Takes precedence over has_password.
Hide protected postsTry it
$args = array(
  'has_password' => false,
);
$args = [
  'has_password' => false,
];
07

Post Type

Docs ↗

Choose which post types to return.

ParameterTypeDescription
post_typestringstring[]A post type or an array of them. Default 'post', or 'any' when tax_query is set.

Values

post
A post.
page
A page.
revision
A revision.
attachment
Media. Attachments use the 'inherit' status, so set post_status to 'inherit' or 'any'.
nav_menu_item
A classic navigation menu item.
wp_block
A synced pattern (reusable block).
wp_template
A block template.
wp_template_part
A block template part.
wp_navigation
A navigation block menu.
any
Every type except revisions and types with exclude_from_search. Cannot be used inside an array.
Images from the media libraryTry it
$args = array(
  'post_type'      => 'attachment',
  'post_status'    => 'inherit',
  'post_mime_type' => 'image',
);
$args = [
  'post_type'      => 'attachment',
  'post_status'    => 'inherit',
  'post_mime_type' => 'image',
];
08

Post Status

Docs ↗

Choose which statuses to return.

ParameterTypeDescription
post_statusstringstring[]A status or an array of them. Default 'publish', plus 'private' for users who can read private posts.

Values

publish
Published.
pending
Pending review.
draft
Draft.
auto-draft
Newly created, no content yet.
future
Scheduled.
private
Visible only to users with the right capability.
inherit
Revisions and attachments.
trash
In the trash.
any
Every status except 'trash' and 'auto-draft'. Cannot be used inside an array.
Drafts and scheduled postsTry it
$args = array(
  'post_status' => array( 'draft', 'future' ),
);
$args = [
  'post_status' => [ 'draft', 'future' ],
];
09

Comment

Docs ↗

Filter by comment count or discussion settings.

ParameterTypeDescription
comment_count 4.9+intarrayAn integer matches that exact count. An array takes 'value' and 'compare' (=, !=, >, >=, <, <=).
comment_status 4.5+string'open' or 'closed'.
ping_status 4.5+string'open' or 'closed'.
comments_per_pageintComments per page on singular views. Defaults to the comments_per_page option.
At least ten commentsTry it
$args = array(
  'comment_count' => array(
    'value'   => 10,
    'compare' => '>=',
  ),
);
$args = [
  'comment_count' => [
    'value'   => 10,
    'compare' => '>=',
  ],
];
10

Pagination

Docs ↗

Control how many posts are returned and which page of them.

ParameterTypeDescription
posts_per_pageintPosts per page. Use -1 for all. In feeds this is replaced by the posts_per_rss option.
nopagingboolReturn all posts, no paging. Default false.
pagedintPage number, usually get_query_var( 'paged' ).
pageintPage number on a static front page. Also the page of a post split with <!--nextpage-->.
posts_per_archive_pageintOverrides posts_per_page when is_archive() or is_search() is true.
offsetintNumber of posts to skip.
ignore_sticky_posts 3.1+boolStop sticky posts being moved to the front. They still appear in their natural position. Default false.
Paginated archiveTry it
$args = array(
  'posts_per_page' => 10,
  'paged'          => max( 1, get_query_var( 'paged' ) ),
);
$args = [
  'posts_per_page' => 10,
  'paged'          => max( 1, get_query_var( 'paged' ) ),
];
11

Order & Orderby

Docs ↗

Sort the results.

ParameterTypeDescription
orderstring'DESC' (default) or 'ASC'.
orderbystringarrayOne value, several separated by spaces, or an array of field => direction pairs (since 4.0). Default 'date', or 'relevance' when searching.
meta_typestringCast applied to meta_key values when sorting by 'meta_value'. Same types as meta_query.

orderby values

none
No order.
ID
Post ID. Note the capitals.
author
Author ID. Also 'post_author'.
title
Title. Also 'post_title'.
name
Slug. Also 'post_name'.
type
Post type. Also 'post_type'.
date
Publish date. Also 'post_date'.
modified
Last modified date. Also 'post_modified'.
parent
Parent ID. Also 'post_parent'.
rand
Random. 'RAND(5)' uses a seed (since 4.5). Slow on large tables.
comment_count
Number of comments.
relevance
Search relevance: full phrase, then all terms in title, then any term in title, then phrase in content.
menu_order
Page order, then attachment order.
meta_value
Value of meta_key, sorted as text unless meta_type is set.
meta_value_num
Value of meta_key, sorted as a number.
post__in
Keep the order of the post__in array. Ignores order.
post_name__in
Keep the order of the post_name__in array (since 4.6).
post_parent__in
Keep the order of the post_parent__in array (since 4.6).
clause key
The key of a named meta_query clause (since 4.2).
Different direction per fieldTry it
$args = array(
  'orderby' => array(
    'menu_order' => 'ASC',
    'title'      => 'DESC',
  ),
);
$args = [
  'orderby' => [
    'menu_order' => 'ASC',
    'title'      => 'DESC',
  ],
];
Sort by a numeric custom fieldTry it
$args = array(
  'meta_key' => 'price',
  'orderby'  => 'meta_value_num',
  'order'    => 'ASC',
);
$args = [
  'meta_key' => 'price',
  'orderby'  => 'meta_value_num',
  'order'    => 'ASC',
];
12

Date

Docs ↗

Filter by publish or modified date, from simple values to full date ranges.

ParameterTypeDescription
yearintFour-digit year.
monthnumintMonth, 1 to 12.
wintWeek of the year, 0 to 53. Depends on the start_of_week option.
dayintDay of the month, 1 to 31.
hourintHour, 0 to 23.
minuteintMinute, 0 to 59.
secondintSecond, 0 to 59.
mintYear and month together, e.g. 202611.
date_query 3.7+arrayAn array of date clauses. Clauses can be nested.

Keys inside date_query

ParameterTypeDescription
relationstring'AND' (default) or 'OR'. Top level only.
columnstringColumn to compare: 'post_date' (default), 'post_date_gmt', 'post_modified', 'post_modified_gmt'. Top level or per clause.
afterstringarrayA strtotime() string, or an array of year, month, day.
beforestringarrayA strtotime() string, or an array of year, month, day.
inclusiveboolInclude the exact after and before dates. Default false.
year, month, week, dayintint[]Calendar parts: month 1–12, week 1–53, day 1–31.
dayofyearintint[]Day of the year, 1 to 366.
dayofweekintint[]Day of the week, 1 (Sunday) to 7.
dayofweek_iso 4.1+intint[]ISO day of the week, 1 (Monday) to 7.
hour, minute, secondintint[]Time parts: 0–23, 0–59, 0–59.
comparestring= (default), !=, >, >=, <, <=, IN, NOT IN, BETWEEN, NOT BETWEEN. Array values need one of the last four.
Posts from 2025Try it
$args = array(
  'date_query' => array(
    array(
      'after'     => '2025-01-01',
      'before'    => '2025-12-31',
      'inclusive' => true,
    ),
  ),
);
$args = [
  'date_query' => [
    [
      'after'     => '2025-01-01',
      'before'    => '2025-12-31',
      'inclusive' => true,
    ],
  ],
];
Weekend posts since 2025Try it
$args = array(
  'date_query' => array(
    'relation' => 'AND',
    array(
      'dayofweek' => array( 1, 7 ),
      'compare'   => 'IN',
    ),
    array(
      'after' => '2025-01-01',
    ),
  ),
);
$args = [
  'date_query' => [
    'relation' => 'AND',
    [
      'dayofweek' => [ 1, 7 ],
      'compare'   => 'IN',
    ],
    [
      'after' => '2025-01-01',
    ],
  ],
];
13

Custom Field

Docs ↗

Filter by post meta, with simple keys or a full meta_query.

ParameterTypeDescription
meta_keystringstring[]Meta key or keys.
meta_valuestringstring[]Meta value or values.
meta_comparestringOperator for meta_value. Same values as compare below. Default '=', or 'IN' for an array.
meta_compare_key 5.1+stringOperator for meta_key. Same values as compare_key below.
meta_typestringCast for meta_value. Same values as type below.
meta_type_key 5.3+stringCast for meta_key. Only 'BINARY'.
meta_query 3.1+arrayAn array of meta clauses. Clauses can be nested and named.

Keys inside meta_query

ParameterTypeDescription
relationstring'AND' (default) or 'OR'.
keystringstring[]Meta key or keys.
valuestringstring[]Value or values. Leave it out for EXISTS and NOT EXISTS. Arrays only work with IN, NOT IN, BETWEEN, NOT BETWEEN.
comparestring= (default), !=, >, >=, <, <=, LIKE, NOT LIKE, IN, NOT IN, BETWEEN, NOT BETWEEN, REGEXP, NOT REGEXP, RLIKE, EXISTS, NOT EXISTS.
typestring'CHAR' (default), 'NUMERIC', 'BINARY', 'DATE', 'DATETIME', 'DECIMAL', 'SIGNED', 'TIME', 'UNSIGNED'. DECIMAL and NUMERIC accept precision, e.g. 'DECIMAL(10,2)'.
compare_key 5.1+stringOperator for the key: =, !=, LIKE, NOT LIKE, IN, NOT IN, REGEXP, NOT REGEXP, RLIKE, EXISTS, NOT EXISTS.
type_key 5.3+stringCast for the key. Only 'BINARY', for case-sensitive regex.
Blue items priced 1–200, cheapest firstTry it
$args = array(
  'meta_query' => array(
    'relation' => 'AND',
    array(
      'key'   => 'color',
      'value' => 'blue',
    ),
    'price_clause' => array(
      'key'     => 'price',
      'value'   => array( 1, 200 ),
      'type'    => 'NUMERIC',
      'compare' => 'BETWEEN',
    ),
  ),
  'orderby' => 'price_clause',
  'order'   => 'ASC',
);
$args = [
  'meta_query' => [
    'relation' => 'AND',
    [
      'key'   => 'color',
      'value' => 'blue',
    ],
    'price_clause' => [
      'key'     => 'price',
      'value'   => [ 1, 200 ],
      'type'    => 'NUMERIC',
      'compare' => 'BETWEEN',
    ],
  ],
  'orderby' => 'price_clause',
  'order'   => 'ASC',
];
14

Permission

Docs ↗

Include private posts when the current user may see them.

ParameterTypeDescription
permstring'readable' or 'editable'.
Posts the current user can editTry it
$args = array(
  'post_status' => array( 'publish', 'private', 'draft' ),
  'perm'        => 'editable',
);
$args = [
  'post_status' => [ 'publish', 'private', 'draft' ],
  'perm'        => 'editable',
];
15

Mime Type

Docs ↗

Filter attachments by file type.

ParameterTypeDescription
post_mime_typestringstring[]Mime type or types. A bare type such as 'image' matches every subtype.
PDFs and Word filesTry it
$args = array(
  'post_type'      => 'attachment',
  'post_status'    => 'inherit',
  'post_mime_type' => array(
    'application/pdf',
    'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
  ),
);
$args = [
  'post_type'      => 'attachment',
  'post_status'    => 'inherit',
  'post_mime_type' => [
    'application/pdf',
    'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
  ],
];
16

Caching

Docs ↗

Trade cache priming for speed when you don't need the extra data.

ParameterTypeDescription
cache_resultsboolCache post objects and, since 6.1, the query result itself. Default true.
update_post_meta_cacheboolPrime the meta cache. Turn off if you won't read meta. Default true.
update_post_term_cacheboolPrime the term cache. Turn off if you won't read terms. Default true.
update_menu_item_cache 6.1+boolPrime caches for the objects nav menu items point to. Default false.
lazy_load_term_meta 4.6+boolPrime term meta lazily. Defaults to update_post_term_cache.
no_found_rowsboolSkip counting total rows. Faster, but found_posts and max_num_pages become 0, so pagination stops working. Default false.
Lean query for IDs onlyTry it
$args = array(
  'fields'                 => 'ids',
  'no_found_rows'          => true,
  'update_post_meta_cache' => false,
  'update_post_term_cache' => false,
);
$args = [
  'fields'                 => 'ids',
  'no_found_rows'          => true,
  'update_post_meta_cache' => false,
  'update_post_term_cache' => false,
];
18

Return Fields

Docs ↗

Return lighter results than full post objects.

ParameterTypeDescription
fieldsstringWhat to return. Anything other than the values below returns full post objects.

Values

''
Full WP_Post objects. Default.
ids
An array of post IDs.
id=>parent
From get_posts() or $query->query(): parent IDs keyed by post ID. In $query->posts: objects with only ID and post_parent.
Just the IDs
$ids = get_posts( array(
  'post_type' => 'page',
  'fields'    => 'ids',
  'nopaging'  => true,
) );
$ids = get_posts( [
  'post_type' => 'page',
  'fields'    => 'ids',
  'nopaging'  => true,
] );
19

Filters

Docs ↗

Hook into the SQL that WP_Query builds.

ParameterTypeDescription
suppress_filtersboolSkip the posts_* SQL filters. Default false, but get_posts() sets it to true.

Common filters

posts_where
Change the WHERE clause.
posts_join
Change the JOIN clause.
posts_orderby
Change the ORDER BY clause.
posts_clauses
Change all clauses at once.
posts_pre_query
Return posts yourself and skip the database.
found_posts
Adjust the total, for example after using offset.
⋯

One-file version

Download ↓Download ↓

Every top-level parameter in one PHP array with a sample value and a one-line note, for pasting into your editor. It's a reference, not a query to run as-is.

Show the file
wp-query-cheat-sheet.phpwp-query-cheat-sheet-short-arrays.php
<?php
/**
 * WP_Query Cheat Sheet: every WP_Query parameter in one file.
 * Checked against WordPress 7.1. https://clearanceclarence-software.github.io/wp-query-cheat-sheet/
 *
 * Every top-level parameter with a sample value. This is a reference,
 * not a query to run as-is: many of these contradict each other.
 * Nested arrays are shown in full on the site.
 *
 * Inspired by wp-query-ref by luetkemj: https://github.com/luetkemj/wp-query-ref
 */

$args = array(

  // Author: Show posts by, or not by, certain authors.
  // https://developer.wordpress.org/reference/classes/wp_query/#author-parameters
  'author'         => '1,2,3', // (int|string) Author ID, or a comma-separated list of IDs. Prefix an ID with - to exclude it: '-1,-2'.
  'author_name'    => 'jane', // (string) The author's user_nicename, not their display name.
  'author__in'     => array( 2, 6 ), // (int[]) Posts by any of these author IDs. Since 3.7.
  'author__not_in' => array( 2, 6 ), // (int[]) Posts by none of these author IDs. Since 3.7.

  // Category: Show posts in, or not in, certain categories.
  // https://developer.wordpress.org/reference/classes/wp_query/#category-parameters
  'cat'              => 5, // (int|string) Category ID, children included. Comma-separate several IDs; prefix with - to exclude: '-12,-34'.
  'category_name'    => 'staff,news', // (string) Category slug, children included. 'staff,news' matches any; 'staff+news' matches all.
  'category__and'    => array( 2, 6 ), // (int[]) Posts in all of these categories.
  'category__in'     => array( 2, 6 ), // (int[]) Posts in any of these categories. Children are not included.
  'category__not_in' => array( 2, 6 ), // (int[]) Posts in none of these categories. Children are not included.

  // Tag: Show posts with, or without, certain tags.
  // https://developer.wordpress.org/reference/classes/wp_query/#tag-parameters
  'tag'           => 'cooking', // (string) Tag slug. 'bread,baking' matches any; 'bread+baking' matches all.
  'tag_id'        => 5, // (int) Tag ID.
  'tag__and'      => array( 2, 6 ), // (int[]) Posts with all of these tag IDs.
  'tag__in'       => array( 2, 6 ), // (int[]) Posts with any of these tag IDs.
  'tag__not_in'   => array( 2, 6 ), // (int[]) Posts with none of these tag IDs.
  'tag_slug__and' => array( 'red', 'blue' ), // (string[]) Posts with all of these tag slugs.
  'tag_slug__in'  => array( 'red', 'blue' ), // (string[]) Posts with any of these tag slugs.

  // Taxonomy: Query any taxonomy, including custom ones, with boolean logic between clauses.
  // https://developer.wordpress.org/reference/classes/wp_query/#taxonomy-parameters
  'tax_query' => array(
      'relation' => 'AND',
      array(
        'taxonomy' => 'color',
        'field'    => 'slug',
        'terms'    => array( 'red', 'blue' ),
      ),
      array(
        'taxonomy'         => 'category',
        'field'            => 'slug',
        'terms'            => array( 'staff' ),
        'include_children' => false,
        'operator'         => 'NOT IN',
      ),
    ), // (array) An array of clause arrays. Clauses can be nested, each with its own relation. Since 3.1.

  // Post & Page: Fetch specific posts or pages by ID, slug, title or parent.
  // https://developer.wordpress.org/reference/classes/wp_query/#post-page-parameters
  'p'                   => 1, // (int) Post ID.
  'name'                => 'hello-world', // (string) Post slug.
  'title'               => 'Hello World', // (string) Post title, exact match. Since 4.4.
  'page_id'             => 1, // (int) Page ID.
  'pagename'            => 'sample-page', // (string) Page slug. For a child page use 'parent/child'.
  'attachment_id'       => 1, // (int) Attachment ID.
  'post_name__in'       => array( 'hello-world', 'sample-page' ), // (string[]) Posts with any of these slugs. Since 4.4.
  'post_parent'         => 0, // (int) Children of this ID. Use 0 for top-level entries only. Hierarchical post types only.
  'post_parent__in'     => array( 1, 2, 3 ), // (int[]) Posts whose parent is any of these IDs. Since 3.6.
  'post_parent__not_in' => array( 1, 2, 3 ), // (int[]) Posts whose parent is none of these IDs. Since 3.6.
  'post__in'            => array( 1, 2, 3 ), // (int[]) Only these post IDs. Sticky posts are still prepended unless ignore_sticky_posts is set.
  'post__not_in'        => array( 4, 5 ), // (int[]) Exclude these post IDs. Must be an array; a comma-separated string does not work.
  'menu_order'          => 0, // (int) Posts with exactly this menu order.

  // Password: Filter by whether posts are password protected.
  // https://developer.wordpress.org/reference/classes/wp_query/#password-parameters
  'has_password'  => false, // (bool|null) true for posts with a password, false for posts without, null for both. Since 3.9.
  'post_password' => 'multi-pass', // (string) Posts with this exact password. Takes precedence over has_password. Since 3.9.

  // Post Type: Choose which post types to return.
  // https://developer.wordpress.org/reference/classes/wp_query/#post-type-parameters
  'post_type' => array( 'post', 'page' ), // (string|string[]) A post type or an array of them. Default 'post', or 'any' when tax_query is set.

  // Post Status: Choose which statuses to return.
  // https://developer.wordpress.org/reference/classes/wp_query/#status-parameters
  'post_status' => array( 'publish', 'private' ), // (string|string[]) A status or an array of them. Default 'publish', plus 'private' for users who can read private posts.

  // Comment: Filter by comment count or discussion settings.
  // https://developer.wordpress.org/reference/classes/wp_query/#comment-parameters
  'comment_count'     => array( 'value' => 10, 'compare' => '>=' ), // (int|array) An integer matches that exact count. An array takes 'value' and 'compare' (=, !=, >, >=, <, <=). Since 4.9.
  'comment_status'    => 'open', // (string) 'open' or 'closed'. Since 4.5.
  'ping_status'       => 'open', // (string) 'open' or 'closed'. Since 4.5.
  'comments_per_page' => 50, // (int) Comments per page on singular views. Defaults to the comments_per_page option.

  // Pagination: Control how many posts are returned and which page of them.
  // https://developer.wordpress.org/reference/classes/wp_query/#pagination-parameters
  'posts_per_page'         => 10, // (int) Posts per page. Use -1 for all. In feeds this is replaced by the posts_per_rss option.
  'nopaging'               => false, // (bool) Return all posts, no paging. Default false.
  'paged'                  => get_query_var( 'paged' ), // (int) Page number, usually get_query_var( 'paged' ).
  'page'                   => get_query_var( 'page' ), // (int) Page number on a static front page. Also the page of a post split with <!--nextpage-->.
  'posts_per_archive_page' => 10, // (int) Overrides posts_per_page when is_archive() or is_search() is true.
  'offset'                 => 0, // (int) Number of posts to skip.
  'ignore_sticky_posts'    => false, // (bool) Stop sticky posts being moved to the front. They still appear in their natural position. Default false. Since 3.1.

  // Order & Orderby: Sort the results.
  // https://developer.wordpress.org/reference/classes/wp_query/#order-orderby-parameters
  'order'     => 'DESC', // (string) 'DESC' (default) or 'ASC'.
  'orderby'   => array( 'menu_order' => 'ASC', 'date' => 'DESC' ), // (string|array) One value, several separated by spaces, or an array of field => direction pairs (since 4.0). Default 'date', or 'relevance' when searching.
  'meta_type' => 'NUMERIC', // (string) Cast applied to meta_key values when sorting by 'meta_value'. Same types as meta_query.

  // Date: Filter by publish or modified date, from simple values to full date ranges.
  // https://developer.wordpress.org/reference/classes/wp_query/#date-parameters
  'year'       => 2026, // (int) Four-digit year.
  'monthnum'   => 4, // (int) Month, 1 to 12.
  'w'          => 25, // (int) Week of the year, 0 to 53. Depends on the start_of_week option.
  'day'        => 17, // (int) Day of the month, 1 to 31.
  'hour'       => 13, // (int) Hour, 0 to 23.
  'minute'     => 19, // (int) Minute, 0 to 59.
  'second'     => 30, // (int) Second, 0 to 59.
  'm'          => 202604, // (int) Year and month together, e.g. 202611.
  'date_query' => array(
      array(
        'after'     => '2025-01-01',
        'before'    => '2025-12-31',
        'inclusive' => true,
      ),
    ), // (array) An array of date clauses. Clauses can be nested. Since 3.7.

  // Custom Field: Filter by post meta, with simple keys or a full meta_query.
  // https://developer.wordpress.org/reference/classes/wp_query/#custom-field-post-meta-parameters
  'meta_key'         => 'price', // (string|string[]) Meta key or keys.
  'meta_value'       => '100', // (string|string[]) Meta value or values.
  'meta_compare'     => '>=', // (string) Operator for meta_value. Same values as compare below. Default '=', or 'IN' for an array.
  'meta_compare_key' => '=', // (string) Operator for meta_key. Same values as compare_key below. Since 5.1.
  'meta_type'        => 'NUMERIC', // (string) Cast for meta_value. Same values as type below.
  'meta_type_key'    => '', // (string) Cast for meta_key. Only 'BINARY'. Since 5.3.
  'meta_query'       => array(
      'relation' => 'AND',
      array(
        'key'   => 'color',
        'value' => 'blue',
      ),
      'price_clause' => array(
        'key'     => 'price',
        'value'   => array( 1, 200 ),
        'type'    => 'NUMERIC',
        'compare' => 'BETWEEN',
      ),
    ), // (array) An array of meta clauses. Clauses can be nested and named. Since 3.1.

  // Permission: Include private posts when the current user may see them.
  // https://developer.wordpress.org/reference/classes/wp_query/#permission-parameters
  'perm' => 'readable', // (string) 'readable' or 'editable'.

  // Mime Type: Filter attachments by file type.
  // https://developer.wordpress.org/reference/classes/wp_query/#mime-type-parameters
  'post_mime_type' => 'image', // (string|string[]) Mime type or types. A bare type such as 'image' matches every subtype.

  // Caching: Trade cache priming for speed when you don't need the extra data.
  // https://developer.wordpress.org/reference/classes/wp_query/#caching-parameters
  'cache_results'          => true, // (bool) Cache post objects and, since 6.1, the query result itself. Default true.
  'update_post_meta_cache' => true, // (bool) Prime the meta cache. Turn off if you won't read meta. Default true.
  'update_post_term_cache' => true, // (bool) Prime the term cache. Turn off if you won't read terms. Default true.
  'update_menu_item_cache' => false, // (bool) Prime caches for the objects nav menu items point to. Default false. Since 6.1.
  'lazy_load_term_meta'    => true, // (bool) Prime term meta lazily. Defaults to update_post_term_cache. Since 4.6.
  'no_found_rows'          => false, // (bool) Skip counting total rows. Faster, but found_posts and max_num_pages become 0, so pagination stops working. Default false.

  // Search: Search post content, with control over columns and matching.
  // https://developer.wordpress.org/reference/classes/wp_query/#search-parameters
  's'              => 'pillow -sofa', // (string) Search terms. Prefix a term with - to exclude it: 'pillow -sofa'. The prefix can be changed with the wp_query_search_exclusion_prefix filter.
  'search_columns' => array( 'post_title', 'post_content' ), // (string[]) Columns to search: 'post_title', 'post_excerpt', 'post_content'. Default all three. Since 6.2.
  'exact'          => false, // (bool) Match the whole field, without wildcards. Default false.
  'sentence'       => false, // (bool) Search the input as one phrase instead of separate terms. Default false.

  // Return Fields: Return lighter results than full post objects.
  // https://developer.wordpress.org/reference/classes/wp_query/#return-fields-parameter
  'fields' => '', // (string) What to return. Anything other than the values below returns full post objects.

  // Filters: Hook into the SQL that WP_Query builds.
  // https://developer.wordpress.org/reference/classes/wp_query/#filters
  'suppress_filters' => false, // (bool) Skip the posts_* SQL filters. Default false, but get_posts() sets it to true.

);

$query = new WP_Query( $args );
<?php
/**
 * WP_Query Cheat Sheet: every WP_Query parameter in one file.
 * Checked against WordPress 7.1. https://clearanceclarence-software.github.io/wp-query-cheat-sheet/
 *
 * Every top-level parameter with a sample value. This is a reference,
 * not a query to run as-is: many of these contradict each other.
 * Nested arrays are shown in full on the site.
 *
 * Inspired by wp-query-ref by luetkemj: https://github.com/luetkemj/wp-query-ref
 */

$args = [

  // Author: Show posts by, or not by, certain authors.
  // https://developer.wordpress.org/reference/classes/wp_query/#author-parameters
  'author'         => '1,2,3', // (int|string) Author ID, or a comma-separated list of IDs. Prefix an ID with - to exclude it: '-1,-2'.
  'author_name'    => 'jane', // (string) The author's user_nicename, not their display name.
  'author__in'     => [ 2, 6 ], // (int[]) Posts by any of these author IDs. Since 3.7.
  'author__not_in' => [ 2, 6 ], // (int[]) Posts by none of these author IDs. Since 3.7.

  // Category: Show posts in, or not in, certain categories.
  // https://developer.wordpress.org/reference/classes/wp_query/#category-parameters
  'cat'              => 5, // (int|string) Category ID, children included. Comma-separate several IDs; prefix with - to exclude: '-12,-34'.
  'category_name'    => 'staff,news', // (string) Category slug, children included. 'staff,news' matches any; 'staff+news' matches all.
  'category__and'    => [ 2, 6 ], // (int[]) Posts in all of these categories.
  'category__in'     => [ 2, 6 ], // (int[]) Posts in any of these categories. Children are not included.
  'category__not_in' => [ 2, 6 ], // (int[]) Posts in none of these categories. Children are not included.

  // Tag: Show posts with, or without, certain tags.
  // https://developer.wordpress.org/reference/classes/wp_query/#tag-parameters
  'tag'           => 'cooking', // (string) Tag slug. 'bread,baking' matches any; 'bread+baking' matches all.
  'tag_id'        => 5, // (int) Tag ID.
  'tag__and'      => [ 2, 6 ], // (int[]) Posts with all of these tag IDs.
  'tag__in'       => [ 2, 6 ], // (int[]) Posts with any of these tag IDs.
  'tag__not_in'   => [ 2, 6 ], // (int[]) Posts with none of these tag IDs.
  'tag_slug__and' => [ 'red', 'blue' ], // (string[]) Posts with all of these tag slugs.
  'tag_slug__in'  => [ 'red', 'blue' ], // (string[]) Posts with any of these tag slugs.

  // Taxonomy: Query any taxonomy, including custom ones, with boolean logic between clauses.
  // https://developer.wordpress.org/reference/classes/wp_query/#taxonomy-parameters
  'tax_query' => [
      'relation' => 'AND',
      [
        'taxonomy' => 'color',
        'field'    => 'slug',
        'terms'    => [ 'red', 'blue' ],
      ],
      [
        'taxonomy'         => 'category',
        'field'            => 'slug',
        'terms'            => [ 'staff' ],
        'include_children' => false,
        'operator'         => 'NOT IN',
      ],
    ], // (array) An array of clause arrays. Clauses can be nested, each with its own relation. Since 3.1.

  // Post & Page: Fetch specific posts or pages by ID, slug, title or parent.
  // https://developer.wordpress.org/reference/classes/wp_query/#post-page-parameters
  'p'                   => 1, // (int) Post ID.
  'name'                => 'hello-world', // (string) Post slug.
  'title'               => 'Hello World', // (string) Post title, exact match. Since 4.4.
  'page_id'             => 1, // (int) Page ID.
  'pagename'            => 'sample-page', // (string) Page slug. For a child page use 'parent/child'.
  'attachment_id'       => 1, // (int) Attachment ID.
  'post_name__in'       => [ 'hello-world', 'sample-page' ], // (string[]) Posts with any of these slugs. Since 4.4.
  'post_parent'         => 0, // (int) Children of this ID. Use 0 for top-level entries only. Hierarchical post types only.
  'post_parent__in'     => [ 1, 2, 3 ], // (int[]) Posts whose parent is any of these IDs. Since 3.6.
  'post_parent__not_in' => [ 1, 2, 3 ], // (int[]) Posts whose parent is none of these IDs. Since 3.6.
  'post__in'            => [ 1, 2, 3 ], // (int[]) Only these post IDs. Sticky posts are still prepended unless ignore_sticky_posts is set.
  'post__not_in'        => [ 4, 5 ], // (int[]) Exclude these post IDs. Must be an array; a comma-separated string does not work.
  'menu_order'          => 0, // (int) Posts with exactly this menu order.

  // Password: Filter by whether posts are password protected.
  // https://developer.wordpress.org/reference/classes/wp_query/#password-parameters
  'has_password'  => false, // (bool|null) true for posts with a password, false for posts without, null for both. Since 3.9.
  'post_password' => 'multi-pass', // (string) Posts with this exact password. Takes precedence over has_password. Since 3.9.

  // Post Type: Choose which post types to return.
  // https://developer.wordpress.org/reference/classes/wp_query/#post-type-parameters
  'post_type' => [ 'post', 'page' ], // (string|string[]) A post type or an array of them. Default 'post', or 'any' when tax_query is set.

  // Post Status: Choose which statuses to return.
  // https://developer.wordpress.org/reference/classes/wp_query/#status-parameters
  'post_status' => [ 'publish', 'private' ], // (string|string[]) A status or an array of them. Default 'publish', plus 'private' for users who can read private posts.

  // Comment: Filter by comment count or discussion settings.
  // https://developer.wordpress.org/reference/classes/wp_query/#comment-parameters
  'comment_count'     => [ 'value' => 10, 'compare' => '>=' ], // (int|array) An integer matches that exact count. An array takes 'value' and 'compare' (=, !=, >, >=, <, <=). Since 4.9.
  'comment_status'    => 'open', // (string) 'open' or 'closed'. Since 4.5.
  'ping_status'       => 'open', // (string) 'open' or 'closed'. Since 4.5.
  'comments_per_page' => 50, // (int) Comments per page on singular views. Defaults to the comments_per_page option.

  // Pagination: Control how many posts are returned and which page of them.
  // https://developer.wordpress.org/reference/classes/wp_query/#pagination-parameters
  'posts_per_page'         => 10, // (int) Posts per page. Use -1 for all. In feeds this is replaced by the posts_per_rss option.
  'nopaging'               => false, // (bool) Return all posts, no paging. Default false.
  'paged'                  => get_query_var( 'paged' ), // (int) Page number, usually get_query_var( 'paged' ).
  'page'                   => get_query_var( 'page' ), // (int) Page number on a static front page. Also the page of a post split with <!--nextpage-->.
  'posts_per_archive_page' => 10, // (int) Overrides posts_per_page when is_archive() or is_search() is true.
  'offset'                 => 0, // (int) Number of posts to skip.
  'ignore_sticky_posts'    => false, // (bool) Stop sticky posts being moved to the front. They still appear in their natural position. Default false. Since 3.1.

  // Order & Orderby: Sort the results.
  // https://developer.wordpress.org/reference/classes/wp_query/#order-orderby-parameters
  'order'     => 'DESC', // (string) 'DESC' (default) or 'ASC'.
  'orderby'   => [ 'menu_order' => 'ASC', 'date' => 'DESC' ], // (string|array) One value, several separated by spaces, or an array of field => direction pairs (since 4.0). Default 'date', or 'relevance' when searching.
  'meta_type' => 'NUMERIC', // (string) Cast applied to meta_key values when sorting by 'meta_value'. Same types as meta_query.

  // Date: Filter by publish or modified date, from simple values to full date ranges.
  // https://developer.wordpress.org/reference/classes/wp_query/#date-parameters
  'year'       => 2026, // (int) Four-digit year.
  'monthnum'   => 4, // (int) Month, 1 to 12.
  'w'          => 25, // (int) Week of the year, 0 to 53. Depends on the start_of_week option.
  'day'        => 17, // (int) Day of the month, 1 to 31.
  'hour'       => 13, // (int) Hour, 0 to 23.
  'minute'     => 19, // (int) Minute, 0 to 59.
  'second'     => 30, // (int) Second, 0 to 59.
  'm'          => 202604, // (int) Year and month together, e.g. 202611.
  'date_query' => [
      [
        'after'     => '2025-01-01',
        'before'    => '2025-12-31',
        'inclusive' => true,
      ],
    ], // (array) An array of date clauses. Clauses can be nested. Since 3.7.

  // Custom Field: Filter by post meta, with simple keys or a full meta_query.
  // https://developer.wordpress.org/reference/classes/wp_query/#custom-field-post-meta-parameters
  'meta_key'         => 'price', // (string|string[]) Meta key or keys.
  'meta_value'       => '100', // (string|string[]) Meta value or values.
  'meta_compare'     => '>=', // (string) Operator for meta_value. Same values as compare below. Default '=', or 'IN' for an array.
  'meta_compare_key' => '=', // (string) Operator for meta_key. Same values as compare_key below. Since 5.1.
  'meta_type'        => 'NUMERIC', // (string) Cast for meta_value. Same values as type below.
  'meta_type_key'    => '', // (string) Cast for meta_key. Only 'BINARY'. Since 5.3.
  'meta_query'       => [
      'relation' => 'AND',
      [
        'key'   => 'color',
        'value' => 'blue',
      ],
      'price_clause' => [
        'key'     => 'price',
        'value'   => [ 1, 200 ],
        'type'    => 'NUMERIC',
        'compare' => 'BETWEEN',
      ],
    ], // (array) An array of meta clauses. Clauses can be nested and named. Since 3.1.

  // Permission: Include private posts when the current user may see them.
  // https://developer.wordpress.org/reference/classes/wp_query/#permission-parameters
  'perm' => 'readable', // (string) 'readable' or 'editable'.

  // Mime Type: Filter attachments by file type.
  // https://developer.wordpress.org/reference/classes/wp_query/#mime-type-parameters
  'post_mime_type' => 'image', // (string|string[]) Mime type or types. A bare type such as 'image' matches every subtype.

  // Caching: Trade cache priming for speed when you don't need the extra data.
  // https://developer.wordpress.org/reference/classes/wp_query/#caching-parameters
  'cache_results'          => true, // (bool) Cache post objects and, since 6.1, the query result itself. Default true.
  'update_post_meta_cache' => true, // (bool) Prime the meta cache. Turn off if you won't read meta. Default true.
  'update_post_term_cache' => true, // (bool) Prime the term cache. Turn off if you won't read terms. Default true.
  'update_menu_item_cache' => false, // (bool) Prime caches for the objects nav menu items point to. Default false. Since 6.1.
  'lazy_load_term_meta'    => true, // (bool) Prime term meta lazily. Defaults to update_post_term_cache. Since 4.6.
  'no_found_rows'          => false, // (bool) Skip counting total rows. Faster, but found_posts and max_num_pages become 0, so pagination stops working. Default false.

  // Search: Search post content, with control over columns and matching.
  // https://developer.wordpress.org/reference/classes/wp_query/#search-parameters
  's'              => 'pillow -sofa', // (string) Search terms. Prefix a term with - to exclude it: 'pillow -sofa'. The prefix can be changed with the wp_query_search_exclusion_prefix filter.
  'search_columns' => [ 'post_title', 'post_content' ], // (string[]) Columns to search: 'post_title', 'post_excerpt', 'post_content'. Default all three. Since 6.2.
  'exact'          => false, // (bool) Match the whole field, without wildcards. Default false.
  'sentence'       => false, // (bool) Search the input as one phrase instead of separate terms. Default false.

  // Return Fields: Return lighter results than full post objects.
  // https://developer.wordpress.org/reference/classes/wp_query/#return-fields-parameter
  'fields' => '', // (string) What to return. Anything other than the values below returns full post objects.

  // Filters: Hook into the SQL that WP_Query builds.
  // https://developer.wordpress.org/reference/classes/wp_query/#filters
  'suppress_filters' => false, // (bool) Skip the posts_* SQL filters. Default false, but get_posts() sets it to true.

];

$query = new WP_Query( $args );