Post
For loop type post
, page
, and custom post type, here are the query parameters and fields.
Supported query parameters
Order
order
- Order:asc
(ascending) ordesc
(descending)
Type: string
Default:asc
orderby
- Order by one of:id
,author
,title
,name
,type
,date
,modified
,random
,comment_count
,relevance
,menu
Type: string
Default:title
orderby_field
- Order by custom field
Type: stringorderby_field_number
- Order by custom field whose value is a number
Type: string
Core post meta
include
- Include by ID or name
Type: string, arrayexclude
- Exclude by ID or name
Type: string, arrayid
- Get attachment by ID(s)
Type: string, arrayname
- Name/slug
Type: string, arrayauthor
- Include by author ID, login name, orcurrent
Type: string, arrayexclude_author
- Exclude by author ID, login name, orcurrent
Type: string, arraypublish_compare
- Publish date comparison - One of:before
,before_inclusive
,after
,after_inclusive
Type: stringpublish_date
- Filter by publish date in Y-M-D format,today
,X days ago
and other values compatible with strtotime() - Optionally use "publish_compare" attribute.
Type: string
The example below will display posts that have been published in the past two weeks.<Loop type=post publish_compare="after" publish_date="2 weeks ago">
publish_day
- Filter by given publish day of the month, from 1 to 31, orcurrent
Type: numberpublish_month
- Filter by given publish month, from 1 to 12, orcurrent
Type: numberpublish_week
- Filter by given publish week, from 1 to 54, orcurrent
- Note: the "publish_compare" attribute is not supported for this field
Type: numberpublish_year
- Filter by given publish year, orcurrent
status
- Post status: 'publish' (default), 'pending',draft
,future
,private
,trash
Type: string, array
Default:publish
sticky
- Affects the behavior of sticky posts. Set totrue
to put sticky posts at the beginning of the loop,false
to exclude sticky posts from the loop, andonly
to loop through only sticky posts and ignore non-sticky posts.
Type: stringtype
- Post type(s)
Type: string, array
Default:post
Custom post meta
custom_date_field
- Filter by given custom date field. See filtering the loop for information on when this attribute should be used.
Type: string
The example below will display posts in an "event" custom post type that has an "event_date_time" custom field before the current date (i.e. past events)<Loop type=event custom_date_field=event_date_time custom_date_field_format="Y-m-d H:i:s" custom_date_field_compare=before custom_date_field_value=current>
custom_date_field_compare
- Compare using one of:equal
(default),not
,before
,before_inclusive
,after
,after_inclusive
Type: stringcustom_date_field_format
- For custom date field query, specify the date format of the field value - Default is "Ymd"; For date-time field, set "Y-m-d H:i:s". If it's a timestamp, use "timestamp". For custom field plugins other than ACF, you may need to use a different format.
Type: stringcustom_date_field_type
- For custom date field query, one of:date
(default),time
,datetime
,number
Type: stringcustom_date_field_value
- Filter by given custom date field value, orcurrent
Type: stringcustom_field
- Filter by given custom field. Use with the "custom_field_compare", "custom_field_value", and "custom_field_type" parameters. See filtering the loop for information on when this attribute should be used.
Type: string
The example below will display posts that have a "news_type" custom field that is not equal to "exclusive."<Loop type=post custom_field=news_type custom_field_compare=not custom_field_value=exclusive>
custom_field_*
- See attribute "custom_field", use up to 3 unique filters by appending with number
Type: stringcustom_field_compare
- Compare using one of:equal
(default),not
,before
,before_inclusive
,after
,after_inclusive
Type: stringcustom_field_compare_*
- See attribute "custom_field_compare", use up to 3 unique filters by appending with number
Type: stringcustom_field_type
- For custom field query, one of:string
(default),number
,date
,time
,datetime
Type: stringcustom_field_type_*
- See attribute "custom_field_type", use up to 3 unique filters by appending with number
Type: stringcustom_field_value
- Filter by given custom field value
Type: stringcustom_field_value_*
- See attribute "custom_field_value", use up to 3 unique filters by appending with number
Type: string
Taxonomy
category
- Include by category ID, slug, orcurrent
Type: string, arrayexclude_category
- Exclude by category ID, slug, orcurrent
Type: string, arraytag
- Include by tag ID, slug, orcurrent
Type: string, arrayexclude_tag
- Exclude by tag ID, slug, orcurrent
Type: string, arraychild_terms
- Settrue
to include child terms for hierarchical taxonomies
Type: stringtaxonomy
- Include by taxonomy ID, slug, or "current" for taxonomy archive
Use with "term" and "taxonomy_compare" attributes
Type: string, numbertaxonomy_*
- See attribute "taxonomy", use up to 3 unique filters by appending with number
Type: string, numbertaxonomy_compare
- One ofin
(default),not
,and
,exists
, andnot exists
Use with "taxonomy" attribute
Type: stringtaxonomy_compare_*
- See attribute "taxonomy_compare", use up to 3 unique filters by appending with number
Type: stringtaxonomy_relation
- When using more than one "taxonomy" queries, can specifyand
oror
Type: stringterms
- Include by taxonomy term ID, slug, orcurrent
Use with "taxonomy" attribute
Type: string, number, arrayterms_*
- See attribute "terms", use up to 3 unique filters by appending with number
Type: string, number, array
Pagination & Extras
page
- Page number
Type: number
Default: 1paged
- Posts per page
Type: number
Default: -1search
- Search by given keyword - Prepending a keyword with a hyphen "-" will exclude posts matching it.
Type: string
The example below will display posts in a "course" custom post type that match a search, where the value of that search is defined by a URL query called "keywords."<Loop type=course search="{Url query=keywords}">
Supported fields
Core fields
all
- Shows all custom fields (for development purposes)id
- IDname
- name/slugmenu_order
- Menu orderpost_class
- Post classesurl
- URLedit_url
- Edit URLstatus
- Statustype
- Post typepublish_date
- Publish datemodify_date
- Modify dateauthor
- Authorauthor_*
- Author's user field where the asterisk can be replaced with any field from the user loop such asauthor_avatar_url
.title
- Titleimage
- Featured imageimage_*
- Featured image field where the asterisk can be replaced with any field from the attachment loop such as image_url.excerpt
- Excerpt. For post excerpts, the attribute auto=true can be used to optionally generate an excerpt from post content for posts that don't already have content in their excerpt field.<Field excerpt auto=true />
Attributes to customize:
words
Maximum number of words - default 55more
Text to display after content is trimmed - default: […]
content
- Content
Hierarchical
Data representing post's hierarchical relationships with other posts
ancestors
- Ancestor posts from lowest to highest level; Set reverse=true to go from top-level downchildren
- Childrenchildren_ids
- Children IDsparent
- Parentparent_*
- Parent field where the asterisk can be replaced with any field from the post loop such as parent_title.parent_ids
- All parent IDs from current to top.
Examples
- How to display a random post when your hosting provider has disabled random sorting
- How to display a custom field that contains an image
- How to create loops within loops within loops
- How to only show posts with a certain custom field filled out
- How to show posts only if they exist and display a message if they don’t exist
- How to adjust the resolution or size of a featured image
- How to display a post editing link only when the current user is the post's author
- How to display term fields on a taxonomy term archive