Support

Account

Home Forums General Issues Converting ACF field values to JS Array Reply To: Converting ACF field values to JS Array

  • This $date_field_array = get_field('event_the_date'); only gets a single value from a single post.

    To get all values from all posts you first need to do a query to get all the posts, then you need to loop though all of those posts and get the field from each post.

    
    $args = array(/* your query args here */);
    $my_query = new WP_Query($args);
    if ($my_query->have_posts()) {
      $dates = array();
      while (($my_query->have_posts()) {
        $my_query->the_post();
        $dates[] = get_field('event_the_date');
      }
      // output dates to JS here
    }