【发布时间】:2020-11-23 01:09:53
【问题描述】:
我正在尝试从 wordpress 中自定义帖子类型中的日期字段中获取日期,然后将日期传输到数组中。 然后将该数组转换为 js 对象。 该 js 对象在带有 beforeShowDay 的日期选择器中使用,但它不起作用。 我得到了日期选择器,但没有日期不可用。
如果我这样做:
print_r($dates);
在 php 部分我得到: 数组([0] => 20200829 [1] => 20200821)
这是我的代码:
$dates = [];
$args = array('post_type' => 'cus_booking');
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
the_excerpt();
the_field('start_date');
array_push($dates,get_field('start_date'));
endwhile;
?>
<input type="text" id="datepicker">
<script>
<?php
$js_array = json_encode($dates);
echo "var javascript_array = ". $js_array . ";\n";
?>
jQuery(document).ready(function($) {
$("#datepicker").datepicker({
beforeShowDay: function(date){
var string = jQuery.datepicker.formatDate('yy-mm-dd', date);
return [ javascript_array.indexOf(string) == -1 ]
}
}
);
});
</script>
<?php
wp_reset_postdata();
?>
【问题讨论】:
-
看起来您正在比较不同的格式和字符串与数字
标签: jquery wordpress datepicker