Home › Forums › Add-ons › Repeater Field › Load Repeater Images via AJAX › Reply To: Load Repeater Images via AJAX
Any progress with this? I’m trying to do something similar, but pulling values from a repeater field in another page to a popup box on another. I’ve managed to get the first result, using ajax, but I’m unsure how to pull in all of the values.
This is my code that’s pulling in a single value from the repeater field:
$field.change(function () { // $field = select dropdown
var post_id = $(this).val(); // value of select dropdown = page id where repeater is located
var postData = {
action : 'data_fetch',
'post_id' : post_id
}
var $customList = $(this).closest('.acf-row').find('#modal .checkbox-list-custom'); // element I'm displaying data in (i have multiple divs I want to populate with values)
$.post( ajaxurl, postData ).done(function(result) {
var resultLower = result.toLowerCase();
var result = $('<li><label><input id="test" type="checkbox" value="'+resultLower+'">'+result+'</label></li>');
$customList.empty(); // emptying the div of any previous data
$customList.append(result); // appending results to div
});
$(this).closest('.acf-row').find('#modal:eq(0)').addClass('visible'); // making relevant div visible after the above has completed
});
add_action('wp_ajax_data_fetch', 'data_fetch'); // logged in users
add_action('wp_ajax_nopriv_data_fetch', 'data_fetch'); // other users
function data_fetch(){
$post_id = filter_input( INPUT_POST, 'post_id' );
$array = array();
if(have_rows('new_colour', $post_id)) :
while(have_rows('new_colour', $post_id)) : the_row();
$array = get_sub_field('colour_name', $post_id);
foreach ($array as $item) {
$array[$array] = $item;
}
endwhile;
endif;
wp_send_json($array); //Use WP send json function
wp_die();
}
I don’t know whether my partial answer will be of any use, but if you manage to adjust any of it to pull in all values I’d be very interested in seeing what you come up with.
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!
The most recent ACF Chat Friday featured a live demo of how to register CPTs directly in the plugin, one of our most requested features. Check out the summary below for a replay of the demo, and don’t forget to register for the next session! https://t.co/k2KQ3WWBAz
— Advanced Custom Fields (@wp_acf) March 9, 2023
© 2023 Advanced Custom Fields.
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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.