admin管理员组

文章数量:1431391

I need to save advanced custom fields data before calling another function on the post. One way I thought of doing this is to add another button (near the fields) to save the post. Is this possible? thanks

I need to save advanced custom fields data before calling another function on the post. One way I thought of doing this is to add another button (near the fields) to save the post. Is this possible? thanks

Share Improve this question asked Apr 15, 2019 at 22:44 JustinJustin 135 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 0
  $settings = array(
                      'form' => false,
                    //  'field_groups' => array(290),
                      'fields' => array( 'field_5ba88d1dee1ef' ),
                    );

                    acf_form( $settings );

In the above code you can add the multiple fields in the fields attribute. Inside the array you can add the key of the acf fields as many as you want. If you want to show the whole group of the fields then you can pass the group id in the field_groups array.

After this code you can place the button for submission of the acf_fields.On the click of the button add the jquery code to run ajax.

Like this.

 jQuery(document).ready(function(){
jQuery('#save_now').click(function(){      

  jQuery.ajax({
    type : 'POST',
    url  : ajax_object.ajaxurl,
    data : {
      'action' : 'save_acf_fields',

    },
    success : function(response){
      location.reload();

    },
  });
});

});

And on the ajax function you can get the acf filds value like this.

   $acf_form = $_POST["acf"];
   $mul_galleries = $acf_form["field_5ba88d1dee1ef"];     

Yes you can save the advance custom field data before calling another function using ajax. On the click of the button you can send the acf fields to the ajax function.

On the ajax function you can store them or apply any logic that you want.

本文标签: Save ACF with a save button on a post