This is my final code so far ! And its working .. Thanks John
<script>
<?php
$ea_args = array(
'post_type' => 'event-main',
'posts_per_page' => -1,
);
$ea_query = new WP_Query( $ea_args );
if ( $ea_query->have_posts() ) {
$dates_enable = array();
while ( $ea_query->have_posts() ) {
$ea_query->the_post();
$dates_enable[] = get_field('event_the_date');
}
$dates_js_array = json_encode($dates_enable);
} // end if
wp_reset_query();
?>
var enableDays = <?php echo $dates_js_array; ?>;
console.log(enableDays);
</script>
I have tried this , but the JS array remains empty. Can you please give an example of converting this $dates[] to a JS array variable ?
Thanks for your Reply John..
I am trying to get all the values of “event_the_date” from all the available custom post type. Then converting this array of values to a js array