WordPress Query Reference

/**
* CODEX: http://codex.wordpress.org/Class_Reference/WP_Query#Parameters
* Source: https://core.trac.wordpress.org/browser/tags/4.9.4/src/wp-includes/query.php
*/
// Author Parameters – Show posts associated with certain author.
// http://codex.wordpress.org/Class_Reference/WP_Query#Author_Parameters

$args = array(
'author' => '1,2,3,', // (int | string) - use author id or comma-separated list of IDs [use minus (-) to exclude authors by ID ex. 'author' => '-1,-2,-3,']
'author_name' => 'luetkemj', // (string) - use 'user_nicename' (NOT name)
'author__in' => array( 2, 6 ), // (array) - use author id (available with Version 3.7).
'author__not_in' => array( 2, 6 ), // (array)' - use author id (available with Version 3.7).

// Category Parameters - Show posts associated with certain categories.
// http://codex.wordpress.org/Class_Reference/WP_Query#Category_Parameters
'cat' => 5, // (int) - Display posts that have this category (and any children of that category), using category id.
'cat' => '-12,-34,-56' // Display all posts except those from a category by prefixing its id with a '-' (minus) sign.
'category_name' => 'staff, news', // (string) - Display posts that have these categories (and any children of that category), using category slug.
'category_name' => 'staff+news', // (string) - Display posts that have "all" of these categories, using category slug.
'category__and' => array( 2, 6 ), // (array) - Display posts that are in multiple categories. This shows posts that are in both categories 2 and 6.
'category__in' => array( 2, 6 ), // (array) - Display posts that have this category (not children of that category), using category id.
'category__not_in' => array( 2, 6 ), // (array) - Display posts that DO NOT HAVE these categories (not children of that category), using category id.

// Tag Parameters - Show posts associated with certain tags.
// http://codex.wordpress.org/Class_Reference/WP_Query#Tag_Parameters
'tag' => 'cooking', // (string) - use tag slug.
'tag_id' => 5, // (int) - use tag id.
'tag__and' => array( 2, 6), // (array) - use tag ids.
'tag__in' => array( 2, 6), // (array) - use tag ids.
'tag__not_in' => array( 2, 6), // (array) - use tag ids.
'tag_slug__and' => array( 'red', 'blue'), // (array) - use tag slugs.
'tag_slug__in' => array( 'red', 'blue'), // (array) - use tag slugs.

// Taxonomy Parameters - Show posts associated with certain taxonomy.
// http://codex.wordpress.org/Class_Reference/WP_Query#Taxonomy_Parameters
// Important Note: tax_query takes an array of tax query arguments arrays (it takes an array of arrays)
// This construct allows you to query multiple taxonomies by using the relation parameter in the first (outer) array to describe the boolean relationship between the taxonomy queries.
'tax_query' => array( // (array) - use taxonomy parameters (available with Version 3.1).
'relation' => 'AND', // (string) - The logical relationship between each inner taxonomy array when there is more than one. Possible values are 'AND', 'OR'. Do not use with a single inner taxonomy array. Default value is 'AND'.
array(
'taxonomy' => 'color', // (string) - Taxonomy.
'field' => 'slug', // (string) - Select taxonomy term by Possible values are 'term_id', 'name', 'slug' or 'term_taxonomy_id'. Default value is 'term_id'.
'terms' => array( 'red', 'blue' ), // (int/string/array) - Taxonomy term(s).
'include_children' => true, // (bool) - Whether or not to include children for hierarchical taxonomies. Defaults to true.
'operator' => 'IN' // (string) - Operator to test. Possible values are 'IN', 'NOT IN', 'AND', 'EXISTS' and 'NOT EXISTS'. Default value is 'IN'.
),
array(
'taxonomy' => 'actor',
'field' => 'id',
'terms' => array( 103, 115, 206 ),
'include_children' => false,
'operator' => 'NOT IN'
)
),

// Post & Page Parameters - Display content based on post and page parameters.
// http://codex.wordpress.org/Class_Reference/WP_Query#Post_.26_Page_Parameters
'p' => 1, // (int) - use post id.
'name' => 'hello-world', // (string) - use post slug.
'title' => 'Hello World' // (string) - use post title (available with Version 4.4)
'page_id' => 1, // (int) - use page id.
'pagename' => 'sample-page', // (string) - use page slug.
'pagename' => 'contact_us/canada', // (string) - Display child page using the slug of the parent and the child page, separated ba slash
'post_name__in' => 'sample-post' (array) // - use post slugs. Specify posts to retrieve. (available since Version 4.4)
'post_parent' => 1, // (int) - use page id. Return just the child Pages. (Only works with heirachical post types.)
'post_parent__in' => array(1,2,3) // (array) - use post ids. Specify posts whose parent is in an array. NOTE: Introduced in 3.6
'post_parent__not_in' => array(1,2,3), // (array) - use post ids. Specify posts whose parent is not in an array.
'post__in' => array(1,2,3), // (array) - use post ids. Specify posts to retrieve. ATTENTION If you use sticky posts, they will be included (prepended!) in the posts you retrieve whether you want it or not. To suppress this behaviour use ignore_sticky_posts
'post__not_in' => array(1,2,3), // (array) - use post ids. Specify post NOT to retrieve.
// NOTE: you cannot combine 'post__in' and 'post__not_in' in the same query

// Password Parameters - Show content based on post and page parameters. Remember that default post_type is only set to display posts but not pages.
// http://codex.wordpress.org/Class_Reference/WP_Query#Password_Parameters
'has_password' => true, // (bool) - available with Version 3.9
// true for posts with passwords;
// false for posts without passwords;
// null for all posts with and without passwords
'post_password' => 'multi-pass', // (string) - show posts with a particular password (available with Version 3.9)

// Post Type Parameters - Show posts associated with certain type or status.
// http://codex.wordpress.org/Class_Reference/WP_Query#Type_Parameters
'post_type' => array( // (string / array) - use post types. Retrieves posts by Post Types, default value is 'post';
'post', // - a post.
'page', // - a page.
'revision', // - a revision.
'attachment', // - an attachment. The default WP_Query sets 'post_status'=>'published', but atchments default to 'post_status'=>'inherit' so you'll need to set the status to 'inherit' or 'any'.
'nav_menu_item' // - a navigation menu item
'my-custom-post-type', // - Custom Post Types (e.g. movies)
),
// NOTE: The 'any' keyword available to both post_type and post_status queries cannot be used within an array.
'post_type' => 'any', // - retrieves any type except revisions and types with 'exclude_from_search' set to true.

// Post Status Parameters - Show posts associated with certain type or status.
// http://codex.wordpress.org/Class_Reference/WP_Query#Status_Parameters
'post_status' => array( // (string | array) - use post status. Retrieves posts by Post Status, default value i'publish'.
'publish', // - a published post or page.
'pending', // - post is pending review.
'draft', // - a post in draft status.
'auto-draft', // - a newly created post, with no content.
'future', // - a post to publish in the future.
'private', // - not visible to users who are not logged in.
'inherit', // - a revision. see get_children.
'trash', // - post is in trashbin (available with Version 2.9).
),
// NOTE: The 'any' keyword available to both post_type and post_status queries cannot be used within an array.
'post_status' => 'any', // - retrieves any status except those from post types with 'exclude_from_search' set to true.

// Comment Paremters - @since Version 4.9 Introduced the `$comment_count` parameter.
// https://codex.wordpress.org/Class_Reference/WP_Query#Comment_Parameters
'comment_count' => 10 // (int | array) The amount of comments your CPT has to have ( Search operator will do a '=' operation )
'comment_count' => array(
'value' => 10 // (int) - The amount of comments your CPT has to have when comparing
'compare' => '=' // (string) - The search operator. Possible values are '=', '!=', '>', '>=', '<', '<='. Default value is '='. ) // Pagination Parameters //http://codex.wordpress.org/Class_Reference/WP_Query#Pagination_Parameters 'posts_per_page' => 10, // (int) - number of post to show per page (available with Version 2.1). Use 'posts_per_page' => -1 to show all posts.
// Note: if the query is in a feed, wordpress overwrites this parameter with the stored 'posts_per_rss' option. Treimpose the limit, try using the 'post_limits' filter, or filter 'pre_option_posts_per_rss' and return -1
'nopaging' => false, // (bool) - show all posts or use pagination. Default value is 'false', use paging.
'paged' => get_query_var('paged'), // (int) - number of page. Show the posts that would normally show up just on page X when usinthe "Older Entries" link.
// NOTE: Use get_query_var('page'); if you want your query to work in a Page template that you've set as your static front page. The query variable 'page' holds the pagenumber for a single paginated Post or Page that includes the

Pages: 1 2 3