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
}
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.