WordPress 网站中 WP_Query 类初始化的参数列表3

2018-07-01 0 By admin

十一、日期参数

显示与特定时间和日期期间关联的帖子。

'year' => 2014,   //(int) - 4 digit year (e.g. 2011).
'monthnum' => 4,  //(int) - Month number (from 1 to 12).
'w' =>  25,   //(int) - Week of the year (from 0 to 53).
'day' => 17,  //(int) - Day of the month (from 1 to 31).
'hour' => 13,   //(int) - Hour (from 0 to 23).
'minute' => 19,   //(int) - Minute (from 0 to 60).
'second' => 30,   //(int) - Second (0 to 60).
'm' => 201404,  //(int) - YearMonth (For e.g.: 201307).
'date_query' => array(  //(array) - Date parameters (available with Version 3.7).these are super powerful.
  array(
  'year' => 2014,
  'month' => 4
  'week' => 31
  'day' => 5
  'hour' => 2
  'minute' => 3
  'second' => 36
  'after'   => 'January 1st, 2013', 
  'before'  => array(
  'year'  => 2013,
  'month' => 2,
  'day'   => 28,
  ),
  'inclusive' => true,
  'compare' =>  '=',
  'column' => 'post_date',
  'relation' => 'AND',
  ),
),

十二、自定义字段参数

显示与某个自定义域关联的文章。

'meta_key' => 'key',  //(string) - Custom field key.
'meta_value' => 'value',  //(string) - Custom field value.
'meta_value_num' => 10,   //(number) - Custom field value.
'meta_compare' => '=',  //(string) - Operator to test the 'meta_value'. 
'meta_query' => array(  //(array) - Custom field parameters (available with Version 3.1).
   'relation' => 'AND',   //(string) - Possible values are 'AND', 'OR'.
   array(
   'key' => 'color',  //(string) - Custom field key.
   'value' => 'blue'  //(string/array)
   'type' => 'CHAR',  //(string)
   'compare' => '='   //(string)
   ),
   array(
   'key' => 'price',
   'value' => array( 1,200 ),
   'compare' => 'NOT LIKE'
   )
), 

十三、权限参数

如果用户具有适当的能力,则显示已发布的帖子和私人帖子:

'perm' => 'readable'//(string) Possible values are 'readable', 'editable'

十四、缓存参数

NOTE 缓存是件好事。一般不建议将这些设置为false。

'cache_results' => true,  //(bool) Default is true - Post information cache.
'update_post_term_cache' => true, //(bool) Default is true - Post meta information cache.
'update_post_meta_cache' => true, //(bool) Default is true - Post term information cache.
'no_found_rows' => false,   //(bool) Default is false. 

十五、搜索参数

's' => $s,  //(string) - Passes along the query string variable from a search.
'exact' => true,  //(bool) - flag to make it only match whole titles/posts
'sentence' => true,   //(bool) - flag to make it do a phrase search

十六、后置字段参数

'fields' => 'ids'   //(string) - Which fields to return. All fields are returned by default. 
//Possible values: 
//'ids'  - Return an array of post IDs. 
//'id=>parent' - Return an associative array [ parent => ID, … ].