Swift Templates WP_Query Arguments

Posts Per Page

'posts_per_page' => 10

Number of post to show per page. Use -1 to show all posts.

Order

'order' => 'DESC'

(string) - Designates the ascending or descending order of the 'orderby' parameter. Default to 'DESC'.

Possible Values


  • 'ASC' - ascending order from lowest to highest values (1, 2, 3; a, b, c).
  • 'DESC' - descending order from highest to lowest values (3, 2, 1; c, b, a).

Order By

'orderby' => 'date'

(string) - Sort retrieved posts by parameter. Defaults to 'date'.

Possible Values


  • 'none' - No order (available with Version 2.8).
  • 'ID' - Order by post id. Note the capitalization.
  • 'author' - Order by author.
  • 'title' - Order by title.
  • 'date' - Order by date.
  • 'modified' - Order by last modified date.
  • 'parent' - Order by post/page parent id.
  • 'rand' - Random order.
  • 'comment_count' - Order by number of comments (available with Version 2.9).
  • 'menu_order' - Order by Page Order. Used most often for Pages (Order field in the EdiPage Attributes box) and for Attachments (the integer fields in the Insert / Upload MediGallery dialog), but could be used for any post type with distinct 'menu_order' values (theall default to 0).
  • 'meta_value' - Note that a 'meta_key=keyname' must also be present in the query. Note alsthat the sorting will be alphabetical which is fine for strings (i.e. words), but can bunexpected for numbers (e.g. 1, 3, 34, 4, 56, 6, etc, rather than 1, 3, 4, 6, 34, 56 as yomight naturally expect).
  • 'meta_value_num' - Order by numeric meta value (available with Version 2.8). Also notthat a 'meta_key=keyname' must also be present in the query. This value allows for numericasorting as noted above in 'meta_value'.
  • 'post__in' - Preserve post ID order given in the post__in array (available with Version 3.5).

Author ID

'author' => 1,2,3,

(int) - use author id [use minus (-) to exclude authors by ID ex. 'author' => -1,-2,-3,]

Author Nicename (not name)

'author_name' => 'luetkemj'

(string) - use 'user_nicename' (NOT name)

Category ID

'cat' => 5

(int) - use category id.

Category Slug

'category_name' => 'staff', 'news'

(string) - use category slug (NOT name).

Tag ID

'tag_id' => 5

(int) - use tag id.

Tag Slug

'tag' => 'cooking'

(string) - use tag slug.

Post Parent ID

'post_parent' => 1

(int) - use page id. Return just the child Pages.

Year

'year' => 2012

(int) - 4 digit year (e.g. 2011).

Month

'monthnum' => 3

(int) - Month number (from 1 to 12).

Week

'w' => 25

(int) - Week of the year (from 0 to 53). Uses the MySQL WEEK command. The mode is dependenon the "start_of_week" option.

Day

'day' => 17

(int) - Day of the month (from 1 to 31).

Hour

'hour' => 13

(int) - Hour (from 0 to 23).

Minute

'minute' => 19

(int) - Minute (from 0 to 60).

Second

'second' => 30

(int) - Second (0 to 60).

Meta Key

'meta_key' => 'key'

(string) - Custom field key.

Meta Value

'meta_value' => 'value'

(string) - Custom field value.

Meta Value Numeric

'meta_value_num' => 10

(number) - Custom field value.

Meta Compare

'meta_compare' => '='

(string) - Operator to test the 'meta_value'. Possible values are '!=', '>', '>=', '<', or ='. Default value is '='.