WordPress args

Following are common arguments that may be passed to get_posts() query.

Array Parameter
posts_per_page Number of posts displayed per page
offset If you have your blog configured to show just one post on the front page, but also want to list links to the previous five posts in category ID 1, you can use this:
category ID of Category
orderby Sort retrieved posts by parameter. Defaults to ‘date’. One or more options can be passed.

  • ‘none’ – No order
  • ‘ID’ – Order by post id. Note the capitalization.
  • ‘author’ – Order by author.
  • ‘title’ – Order by title.
  • ‘name’ – Order by post name (post slug).
  • ‘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
  • ‘menu_order’ – Order by Page Order. Used most often for Pages. And for Attachments (the integer fields in the Insert / Upload Media Gallery dialog), but could be used for any post type with distinct ‘menu_order’ values (they all default to 0).
  • ‘meta_value’ – Note that a ‘meta_key=keyname’ must also be present in the query. Note also that the sorting will be alphabetical which is fine for strings (i.e. words), but can be unexpected for numbers (e.g. 1, 3, 34, 4, 56, 6, etc, rather than 1, 3, 4, 6, 34, 56 as you might naturally expect). Use ‘meta_value_num’ instead for numeric values.
  • ‘meta_value_num’ – Order by numeric meta value. Also note that a ‘meta_key=keyname’ must also be present in the query. This value allows for numerical sorting as noted above in ‘meta_value’.
  • ‘post__in’ – Preserve post ID order given in the post__in array
order Designates the ascending or descending order of the ‘orderby’ parameter. Defaults to ‘DESC’.

  • ‘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).
include ID of posts with comma like (4,6,3,9)
exclude ID of posts with comma like (4,6,3,9)
(string) (required) The key of the custom field you will edit. (this should be raw as opposed to sanitized for database queries)

Default: None

(mixed) (required) The new value of the custom field. A passed array will be serialized into a string.(this should be raw as opposed to sanitized for database queries)

Default: None

post_type array(‘videos’,’image’,’audio’)
(string) (optional) A full or partial mime-type, e.g. image, video, video/mp4, which is matched against a post’s post_mime_type field.

Default: None

(integer) (optional) Pass the ID of a post or Page to get its children. Pass 0 to get attachments without parent. Pass null to get any child regardless of parent.

Default: ‘0’

(string) (optional) Any value from the post_status column of the wp_posts table, such as publish, draft, or inherit; or the keyword any.

Default: ‘any’

suppress_filters ‘suppress_filters’ => true as default, while query_posts() applies filters by default, this can be confusing when using query-modifying plugins, like WPML. Also note that even if ‘suppress_filters’ is true, any filters attached to pre_get_posts are still applied—only filters attached on ‘posts_*’ or ‘comment_feed_*’ are suppressed.

You may also like...