Changeset 25860
- Timestamp:
- 10/21/2013 11:16:31 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/date.php
r25139 r25860 3 3 * WP_Date_Query will generate a MySQL WHERE clause for the specified date-based parameters. 4 4 * 5 * Initialize the class by passing an array of arrays of parameters. Example: 6 * 7 * $date_query = new WP_Date_Query( array( 8 * 'column' => 'optional, column to query against, default is post_date', 9 * 'compare' => 'optional, see WP_Date_Query::get_compare()', 10 * 'relation' => 'optional, OR or AND, how the sub-arrays should be compared, default is AND', 11 * array( 12 * 'column' => 'see above', 13 * 'compare' => 'see above', 14 * 'after' => 'string or array, see WP_Date_Query::build_mysql_datetime()', 15 * 'before' => 'string or array, see WP_Date_Query::build_mysql_datetime()', 16 * 'inclusive' => 'boolean, for after/before, whether exact value should be matched or not', 17 * 'year' => '4 digit int', 18 * 'month' => 'int, 1-12', 19 * 'week' => 'int, 0-53', 20 * 'day' => 'int, 1-31', 21 * 'hour' => 'int, 0-23', 22 * 'minute' => 'int, 0-60', 23 * 'second' => 'int, 0-60', 24 * ), 25 * array( 26 * ... 27 * ), 28 * ... 29 * ) ); 30 * 31 * Then call the get_sql() method to get the MySQL WHERE string: 32 * 33 * $where .= $date_query->get_sql(); 5 * Initialize the class by passing an array of arrays of parameters. 34 6 * 35 7 * @link http://codex.wordpress.org/Function_Reference/WP_Query Codex page. … … 75 47 76 48 /** 77 * Constructor 78 * 79 * @param array $date_query A date query parameter array, see class descriptor for further details. 80 * @param array (optional) $default_column What column name to query against. Defaults to "post_date". 49 * Constructor. 50 * 51 * @param array $date_query { 52 * One or more associative arrays of date query parameters. 53 * 54 * @type array { 55 * @type string $column Optional. The column to query against. If undefined, inherits the value of 56 * the $default_column parameter. Default 'post_date'. Accepts 'post_date', 57 * 'post_date_gmt', 'post_modified','post_modified_gmt', 'comment_date', 58 * 'comment_date_gmt'. 59 * @type string $compare Optional. The comparison operator. 60 * Default '='. Accepts '=', '!=', '>', '>=', '<', '<=', 'IN', 'NOT IN', 61 * 'BETWEEN', 'NOT BETWEEN'. 62 * @type string $relation Optional. The boolean relationship between the date queryies. 63 * Default 'OR'. Accepts 'OR', 'AND'. 64 * @type array { 65 * @type string|array $before Optional. Date to retrieve posts before. Accepts strtotime()-compatible 66 * string, or array of 'year', 'month', 'day' values. { 67 * 68 * @type string $year The four-digit year. Default empty. Accepts any four-digit year. 69 * @type string $month Optional when passing array.The month of the year. 70 * Default (string:empty)|(array:1). Accepts numbers 1-12. 71 * @type string $day Optional when passing array.The day of the month. 72 * Default (string:empty)|(array:1). Accepts numbers 1-31. 73 * } 74 * @type string|array $after Optional. Date to retrieve posts before. Accepts strtotime()-compatible 75 * string, or array of 'year', 'month', 'day' values. { 76 * 77 * @type string $year The four-digit year. Default empty. Accepts any four-digit year. 78 * @type string $month Optional when passing array.The month of the year. 79 * Default (string:empty)|(array:12). Accepts numbers 1-12. 80 * @type string $day Optional when passing array.The day of the month. 81 * Default (string:empty)|(array:last day of month). Accepts numbers 1-31. 82 * } 83 * @type string $column Optional. Used to add a clause comparing a column other than the column 84 * specified in the top-level $column paramater. Default is the value 85 * of top-level $column. Accepts 'post_date', 'post_date_gmt', 86 * 'post_modified', 'post_modified_gmt', 'comment_date', 'comment_date_gmt'. 87 * @type string $compare Optional. The comparison operator. Default '='. Accepts '=', '!=', 88 * '>', '>=', '<', '<=', 'IN', 'NOT IN', 'BETWEEN', 'NOT BETWEEN'. 89 * @type bool $inclusive Optional. Include results from dates specified in 'before' or 'after'. 90 * Default. Accepts. 91 * @type int $year Optional. The four-digit near number. Default empty. Accepts any 92 * four-digit year. 93 * @type int $month Optional. The two-digit month number. Default empty. Accepts numbers 1-12. 94 * @type int $week Optional. The week number of the year. Default empty. Accepts numbers 0-53. 95 * @type int $day Optional. The day of the month. Default empty. Accepts numbers 1-31. 96 * @type int $hour Optional. The hour of the day. Default empty. Accepts numbers 0-23. 97 * @type int $minute Optional. The minute of the hour. Default empty. Accepts numbers 0-60. 98 * @type int $second Optional. The second of the minute. Default empty. Accepts numbers 0-60. 99 * } 100 * } 101 * } 102 * @param array $default_column Optional. Default column to query against. Default 'post_date'. 103 * Accepts 'post_date', 'post_date_gmt', 'post_modified', 'post_modified_gmt', 104 * 'comment_date', 'comment_date_gmt'. 81 105 */ 82 106 function __construct( $date_query, $default_column = 'post_date' ) { … … 137 161 */ 138 162 public function validate_column( $column ) { 139 if ( ! in_array( $column, apply_filters( 'date_query_valid_columns', array( 'post_date', 'post_date_gmt', 'post_modified', 'post_modified_gmt', 'comment_date', 'comment_date_gmt' ) ) ) ) 163 $valid_columns = array( 164 'post_date', 'post_date_gmt', 'post_modified', 165 'post_modified_gmt', 'comment_date', 'comment_date_gmt' 166 ); 167 /** 168 * Filter the list of valid date query columns. 169 * 170 * @since 3.7.0 171 * 172 * @param array $valid_columns An array of valid date query columns. Defaults are 'post_date', 'post_date_gmt', 173 * 'post_modified', 'post_modified_gmt', 'comment_date', 'comment_date_gmt' 174 */ 175 if ( ! in_array( $column, apply_filters( 'date_query_valid_columns', $valid_columns ) ) ) 140 176 $column = 'post_date'; 141 177 … … 169 205 $where = ''; 170 206 207 /** 208 * Filter the date query WHERE clause. 209 * 210 * @since 3.7.0 211 * 212 * @param string $where WHERE clause of the date query. 213 * @param WP_Date_Query $this The WP_Date_Query instance. 214 */ 171 215 return apply_filters( 'get_date_sql', $where, $this ); 172 216 }
Note: See TracChangeset
for help on using the changeset viewer.