Support

Account

Home Forums Front-end Issues ACF JS API – instance explaination

Unread

ACF JS API – instance explaination

  • Hello ACF team and users,

    I am working with ACF Pro for a very long time, and today I want to create a dynamic planning/agenda with ACF and the JS API, on a web project (nginx / PHP 7 / WordPress 6.4).
    I have multiples ACF forms loaded on my front-end page, and based on the action want
    -add post
    -edit post
    I reload each form via a ajax call and a WP hook.

    
    function flweb_return_add_tour(){    
        acf_form(array(
            'post_id'       => 'new_post',
            'new_post'      => array(
                'post_type'     => 'tours',
                'post_status'   => 'publish'
            ),
        )); 
    }
    add_action('wp_ajax_flweb_return_add_tour', 'flweb_return_add_tour'); // for logged in user
    
    
    $.ajax({
                 method: "POST",
                 url: self.$ajaxurl,
                 data: {
                     action: 'flweb_return_add_tour',
                     date: self.$date,
                     postid: id
                 }
             })
             .done(function (msg) {
                 //remove the old form
                 elem.children('.box-system-box').find('#acf-form').remove();
                 //insert new one
                 elem.children('.box-system-box').append(msg);
                 //reload acf fields
                 acf.do_action('append', $('#bar-add-cmd'));
             });
    

    Is this way the good way ?

    I am wondering if there is another JS way to load the data inside the form via the API. Knowing that I have multiples forms on the same page.
    Thanks for reading me,
    Lola

Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.