Support

Account

Forum Replies Created

  • Inside the custom post type where I’m uploading files, no it’s not using Gutenberg. However, I’ve tested uploading files using both the Gutenberg editor and the classic editor for that post type – same result.

    The same happens for me inside the media library as well, so not sure it’s related to the block editor.

    I’ll put in a support ticket like suggested though. Thanks for your assistance so far! ๐Ÿ™‚

  • Sorry, didn’t see your reply.

    So you’re saying that if you add a field (with “Attachment” set as the location), like shown in my video, your field is displayed within the side panel of the attachment window as soon as any sort of media is uploaded without needing to deselect/reselect the newly-uploaded file? (note: this field shows fine for existing files/uploads, just not immediately when uploading a new file).

    I have no conflicting plugins (only ACF installed). WP & ACF are on the latest versions as well (6.2.2 and 6.1.7).

  • Set as โ€œAttachment = Allโ€, which as far as I can see is the only option for attachments. Same happens if the rule is set to specific file formats as well.

  • Set as “Attachment = All”, which as far as I can see is the only option for attachments. Same happens if the rule is set to specific file formats as well.

  • Thanks for the response, and for finding your code from 1 year and a half ago – much appreciated! Unfortunately I’ve not had any luck with render_template option either. All renders fine within the editor, but nothing on the front end. I’ll keep digging though. Thanks! ๐Ÿ™‚

  • Did you find a fix for this? There’s literally no answers anywhere on why it is happening ๐Ÿ™

  • Why are there no answers to this question!?!??! It’s been asked quite a bit across various sites.

    My issue is essentially the same apart from the JSON for the ACF block is being loaded in the DOM but the block isn’t being rendered. Surely someone has an answer since it’s not a one-off issue that people are experiencing??

  • This is what you’re looking for: https://github.com/philipnewcomer/ACF-Unique-ID-Field ๐Ÿ™‚

    Just install it like you would any other plugin and then you should be able to add a unique ID field to any row, group etc…

  • Hi @bluerhinomiami, yes I did.

    I used the following code in my plugin .php file (or it can go in the functions.php file if you’re not creating a plugin):

    
    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' ); // post id passed from select value via ajax
    
    	$rows = array(); // setup empty array
    	$rows = get_field('new_colour', $post_id); // repeater field
    
    	if($rows)
    	{
    		foreach($rows as $row) // foreach for each repeater row
    		{
    			$array[] = '<li data-id="' . esc_attr( $row['unique_id'] ) . '"><input type="text" name="" value="' . $row['colour_name'] . '"><a class="remove-checkbox dashicons dashicons-trash"></a></li>';
    		}
    	}
    
    	wp_send_json($array); //Use WP send json function - send data back to the page I'm displaying the div on
    }
    

    The $row['unique_id'] section for the data-id is making use of the Unique ID addon for ACF.

    The following js function is what I’m calling when the select box changes:

    
    function reload_colours($el) {
        $el.closest('.acf-row').find('.all-colours span').empty();
        var post_id = $el.closest('.acf-row').find('select').val(); // value of select dropdown = page id where repeater is located
        var data = {
            action: 'data_fetch',
            'post_id': post_id
        }
        var $customList = $el.closest('.acf-row').find('#modal:eq(0) .acf-checkbox-list'); // element I'm displaying data in (i have multiple divs I want to populate with values)
        var dataid = $el.closest('.acf-row').data('id');
        $.post(ajaxurl, data).done(function (result) {
            $customList.find('li').not(':first').remove(); // emptying the div of any previous data
            $customList.append(result); // appending results to div
            $el.closest('.acf-row').find('#modal:eq(0) .acf-checkbox-list input[type="text"]').attr({ 'readonly': true, 'name': 'acf[field_5b55d0491f741][' + dataid + '][field_5bbb6a62912a9][]'});
        });
    }
    

    Basically what’s happening is I’m populating the .acf-checkbox-list div, that is being generated by ACF, with text boxes that contain the values from selected custom post. This is essentially replicating what happens when you click the button to add a new custom checkbox value, and then when you click save it appears that ACF does the work for you in saving the data to the post.

    Hopefully that points you in the right direction.

    If you need my acf json file just let me know.

    EDIT: Forgot to mention that the field keys being used in my ajax call will obviously be different to yours. I just copied the field keys being used by the default “add a custom value” button if I remember correctly.

  • Thanks John! That makes sense, I’ll give this a go and see how it goes. Thanks for the assistance!

  • Did you manage to find an answer to saving items that are populated? I currently have a dynamically populated popup box containing checkboxes that I’d like to save to the post.

  • Just a thought, could you not just use repeater fields as you have done previously but create a simple jQuery function to trigger the add row button, and then focus into the new input, upon pressing the enter key?

    *just noticed the part about not having to paste things individually, which means my advice isn’t really that helpful in this situation – sorry!

  • Just in case anyone stumbles upon this and is trying to do the same I’ve managed to pull in the repeater values using the following (all of which is located in the same file on my setup):

    
    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' ); // post id passed from select value via ajax
    
    	$array = array(); // setup empty array
    	$rows = get_field('new_colour', $post_id); // repeater field
    	if($rows)
    	{
    		foreach($rows as $row) // foreach for each repeater row
    		{
    			$array[] = '<li data-id="' . esc_attr( $row['unique_id'] ) . '"><label><input type="checkbox" value="' . get_the_title($post_id) . " - " . $row['colour_name'] . '">' . $row['colour_name'] . '</label></li>'; // stuff I want to display on the div I'm appending the repeater values to
    		}
    	}
    
    	wp_send_json($array); //Use WP send json function - send data back to the page I'm displaying the div on
    }
    
    
    $field.change(function () { // $field = select dropdown
    
    	var post_id = $(this).val(); // value of select dropdown = page id where repeater is located
    
    	var data = {
    		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, data ).done(function(result) {
    		$customList.empty(); // emptying the div of any previous data
    		$customList.append(result); // appending results to div
    	});					
    	
    	$modal.removeClass('visible'); // hide other open divs for additional select relationship field drop downs
    	$(this).closest('.acf-row').find('#modal:eq(0)').addClass('visible'); // making relevant div visible after the above has completed
    
    });
    

    I’ve not included anything to save the metadata to the post yet, but that shouldn’t be too difficult (famous last words right there).

  • As if by magic, I’ve managed to pull the values in from my repeater field! This is the code I’m using:

    
    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' ); // post id passed from select value via ajax
    
    	$array = array(); // setup empty array
    	$rows = get_field('new_colour', $post_id); // repeater field
    	if($rows)
    	{
    		foreach($rows as $row) // foreach for each repeater row
    		{
    			$array[] = '<li data-id="' . esc_attr( $row['unique_id'] ) . '"><label><input type="checkbox" value="' . get_the_title($post_id) . " - " . $row['colour_name'] . '">' . $row['colour_name'] . '</label></li>'; // stuff I want to display on the div I'm appending the repeater values to
    		}
    	}
    
    	wp_send_json($array); //Use WP send json function - send data back to the page I'm displaying the div on
    }
    
    
    $field.change(function () { // $field = select dropdown
    
    	var post_id = $(this).val(); // value of select dropdown = page id where repeater is located
    
    	var data = {
    		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, data ).done(function(result) {
    		$customList.empty(); // emptying the div of any previous data
    		$customList.append(result); // appending results to div
    	});					
    	
    	$modal.removeClass('visible'); // hide other open divs for additional select relationship field drop downs
    	$(this).closest('.acf-row').find('#modal:eq(0)').addClass('visible'); // making relevant div visible after the above has completed
    
    });
    

    Ended up swapping the while loop for a foreach loop, which for some reason made all of my code start working. Not really sure why, but my headache has disappeared!

    The only thing I’ve not yet done is add in the relevant code to save the metadata to the post, but I’ll try and get that working correctly tomorrow probably.

  • No problem! This seems to be one of the few things that isn’t documented all that much anywhere. I feel like I’ve looked through all of Google so far! Haha.

    Seems like it’s something a few people are looking to achieve, but yet all I find it people pointing people to the “Dynamically populating a select field” post, which I’m sure you’ve probably seen as well!

    Hopefully something relating to this issue appears soon.

  • 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.

Viewing 18 posts - 1 through 18 (of 18 total)