您可以使用WP_Query
要查询从日期A到日期B的帖子,以下是WP_Query
对象:
//////Date Parameters - Show posts associated with a certain time and date period.
//http://codex.wordpress.org/Class_Reference/WP_Query#Date_Parameters
\'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). Uses the MySQL WEEK command. The mode is dependenon the "start_of_week" option.
\'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. check out the codex for more comprehensive code examples http://codex.wordpress.org/Class_Reference/WP_Query#Date_Parameters
array(
\'year\' => 2014, //(int) - 4 digit year (e.g. 2011).
\'month\' => 4 //(int) - Month number (from 1 to 12).
\'week\' => 31 //(int) - Week of the year (from 0 to 53).
\'day\' => 5 //(int) - Day of the month (from 1 to 31).
\'hour\' => 2 //(int) - Hour (from 0 to 23).
\'minute\' => 3 //(int) - Minute (from 0 to 59).
\'second\' => 36 //(int) - Second (0 to 59).
\'after\' => \'January 1st, 2013\', //(string/array) - Date to retrieve posts after. Accepts strtotime()-compatible string, or array of \'year\', \'month\', \'day\'
\'before\' => array( //(string/array) - Date to retrieve posts after. Accepts strtotime()-compatible string, or array of \'year\', \'month\', \'day\'
\'year\' => 2013, //(string) Accepts any four-digit year. Default is empty.
\'month\' => 2, //(string) The month of the year. Accepts numbers 1-12. Default: 12.
\'day\' => 28, //(string) The day of the month. Accepts numbers 1-31. Default: last day of month.
),
\'inclusive\' => true, //(boolean) - For after/before, whether exact value should be matched or not\'.
\'compare\' => \'=\', //(string) - Possible values are \'=\', \'!=\', \'>\', \'>=\', \'<\', \'<=\', \'LIKE\', \'NOT LIKE\', \'IN\', \'NOT IN\', \'BETWEEN\', \'NOT BETWEEN\', \'EXISTS\' (only in WP >= 3.5), and \'NOT EXISTS\' (also only in WP >= 3.5). Default value is \'=\'
\'column\' => \'post_date\', //(string) - Column to query against. Default: \'post_date\'.
\'relation\' => \'AND\', //(string) - OR or AND, how the sub-arrays should be compared. Default: AND.
),
),
资料来源:
https://gist.github.com/luetkemj/2023628