我正在WordPress网站上工作,我有自己的搜索筛选页面,在那里我添加了jquery日期选择器,现在我想按日期选择器搜索帖子?
Html Code
script>
$(function() {
jQuery( "#datepicker-13" ).datepicker({
dateFormat : "yy-mm-dd"
});
$("#datepicker-13").datepicker().datepicker("setDate", new Date());
});
</script>
<input type = "text" name="datefrom" class="form-control alertform" id = "datepicker-13">
Wordpress Query
$datefrom = $_POST[\'datefrom\'];
if(!empty($datefrom) && $datefrom !==\'\')
{
$args = array(
\'post_type\' => \'post\',
\'posts_per_page\' =>8,
\'paged\' => $paged,
\'post_date\' => $datefrom,
\'post_status\' => \'publish\'
);
}
$my_query = new WP_Query($args);
这里是它的解决方案
$datefrom = $_POST[\'datefrom\'];
$time = strtotime($datefrom);
$day = date(\'d\',$time);
$month = date(\'m\',$time);
$year = date(\'Y\',$time);
$args = array(
\'post_type\' => \'post\',
\'posts_per_page\' =>8,
\'paged\' => $paged,
\'date_query\' => array(
array(
\'year\' => $year,
\'month\' => $month,
\'day\' => $day,
),
),
);