WP Code Labs
Search…
Shortcode
The The shortcode [wp_query] is the easiest way to display a custom loop anywhere in your content.

Standard Parameters

The shortcode accepts several parameters:
  • post_type : Comma separated list of post types to query
  • posts_per_page : Integer value of the posts to query
  • category__in : Comma separated list of categories to include
  • category_not_in : Comma separated list of categories to exclude
  • tag__in : Comma separated list of tags to include
  • tag__not_in : Comma separated list of tags to exclude
  • author__in : Comma separated list of authors to include
  • author__not_in: Comma separated list of authors to exclude
  • template : String template name or path to template relative to the theme directory (optional)
  • pagination : True/false whether to use pagination (default: false)
  • ignore_sticky_posts : Whether to ignore sticky posts (default: false)
  • orderby : What to order the posts by
  • order : ASC or DESC sort order
  • context : String context used to filter the query during execution, optional

post_type

A comma separated list of post types to query.
  • Default: post
  • Required: false
  • Type: comma separated list
1
[wp_query post_type="post, page, event"]
Copied!

posts_per_page

Number of post to show per page. Use -1 to show all posts. If combined with the pagination parameter, it will limit the posts per page. If pagination is false, it will limit the total number of posts displayed.
  • Default: wordpress default
  • Required: false
  • Type: integer

category__in

Display posts that have these categories.
  • Default: null
  • Required: false
  • Type: comma seperated list of category names, slugs, or id's

category_not_in

Exclude posts that have these categories.
  • Default: null
  • Required: false
  • Type: comma seperated list of category names, slugs, or id's

tag__in

Display posts that have these tags.
  • Default: null
  • Required: false
  • Type: comma seperated list of tag names, slugs, or id's

tag__not_in

Exclude posts that have these tags.
  • Default: null
  • Required: false
  • Type: comma seperated list of tag names, slugs, or id's

author__in

Display posts by these authors.
  • Default: null
  • Required: false
  • Type: comma seperated list of author names, or id's

author__not_in

Exclude posts by these authors. Accepts name, or id's. Passed as a comma seperated list.
  • Default: null
  • Required: false
  • Type: comma seperated list of author names, or id's

template

Specify the output template. This can be done in one of several ways:
  1. 1.
    By Name: If you've registered your template with the plugin, you can specify the template by name
  2. 2.
    By path: If you have not registered your template, you can specify the path relative to your themes root directory. If a path is specified, the plugin will attempt to load the template if possible.
  • Default: Plugin Default
  • Required: false
  • Type: string
Note: The plugin contains a default template that will be used if no template is specified.
1
[wp_query template="my_custom_template"]
2
3
[wp_query template="my_custom_template.php"]
4
5
[wp_query template="my_template_path/my_custom_template.php"]
6
7
[wp_query template="my_template_path/my_custom_template"]
Copied!

pagination

Whether or not to paginate the posts displayed
  • Default: false
  • Required: false
  • Type: boolean ( true / false )

ignore_sticky_posts

Ignore default sticky post functionality. If set to true, sticky posts will appear in the normal post order. If false, sticky posts will appear first.
  • Default: true
  • Required: no
  • Type: boolean ( true / false )

orderby

What data to order the posts by
  • Default: date
  • Required: no
  • Type: String, see the codex for all options

order

How to order posts
  • Default: DESC
  • Required: no
  • Type: ASC / DESC

context

Optional string used to identify a specific instance, for additional actions and filters.
  • Default: null
  • Required: false
  • Type: string

Dynamic Parameters

The shortcode can also perform custom taxonomy queries using any taxonomy name, in the format:

{tax_name}__in

Display posts that contain this taxonomy terms.
  • Default: null
  • Required: false
  • Type: comma seperated list of term names, slugs, or id's

{tax_name}__not_in

Exclude posts that contain this taxonomy terms.
  • Default: null
  • Required: false
  • Type: comma seperated list of term names, slugs, or id's
Examples
To query all posts of post type "recipe" with the taxonomy of "recipe_type" with the terms "breakfast" or "brunch", and using the "List" template:
1
[wp_query post_type="recipe" recipe_type__in="breakfast, brunch" template="List"]
Copied!
Last modified 2yr ago