Save ACF with a save button on a post

I need to save advanced custom fields data before calling another function on the post. One way I thought of doing this

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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745580770a4634242.html

相关推荐

  • Save ACF with a save button on a post

    I need to save advanced custom fields data before calling another function on the post. One way I thought of doing this

    18小时前
    40

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信