Support

Account

Home Forums ACF PRO Ajax loading acf_from() and no taxonomies fields displayed. Select2 not load.

Solving

Ajax loading acf_from() and no taxonomies fields displayed. Select2 not load.

  • Hi,
    I’m using ajax to display acf_form() to edit posts directlu from front end.
    Here is my single-content.php:

    <?php while ( have_posts() ) : the_post(); ?>
    	<?php $post_id = get_the_ID(); ?>
    	<?php acf_form(array(
    		'post_id'			=> $post_id,
    		'new_post'			=> array(
    			'post_type'			=> 'content',
    			'post_status'		=> 'publish'
    		),
    		'post_title'		=> true,
    		'post_title_label'	=> 'Heading',
    		'submit_value'		=> 'Large',
    		'return' 			=> ''
    	)); ?>
    	<div class="buttons">
    		<a class="btn btn-small btn-back"><?php _e( 'Avbryt', 'cbank' ); ?></a>
    	</div>
    <?php endwhile; ?>

    and some basic js

     $.ajaxSetup({cache:false});
    
        $('#showForm').click(function(){
            var post_link = $(this).attr('href');
    
            $('#form-container').html('<div class="loading"></div>');
            $('#form-container').load(post_link);
            return false;
        });

    Almost all works perfect, except multiselect taxonomies which should be handled by select2 plugin. But it seems that is disable in edit form.

    Any clue about this issue ?

    Thanks in advanced

  • Hi @seska

    Have you seen this guide about acf_form() with AJAX: http://www.advancedcustomfields.com/resources/acf_form/#ajax?

    I hope this helps.

  • Hi James,
    Yes I saw it , but to be honest it’s my first time with ajax and I don’t know where to start.
    I’ve read, that in my called via ajax template should be placed sth like that:

    <script type="text/javascript">
    	(function($) {
    		acf.add_action('load', function( $el ){
    
    		});
    	})(jQuery);
    </script>

    and stuff connected with field.
    But I’m not sure what method should be called.

    I’ve noticed that in form there is no full info about all taxonomy terms, only this which was previously chosen are showing up. So values are not loading.
    Lets say my field key is field_5614c8100ca95.
    How to start ?

  • Hi @seska

    Maybe you can take a look at this article: https://premium.wpmudev.org/blog/using-ajax-with-wordpress/

    I hope this helps.

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

The topic ‘Ajax loading acf_from() and no taxonomies fields displayed. Select2 not load.’ is closed to new replies.