最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Save ACF with a save button on a post

programmeradmin2浏览0评论

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.

发布评论

评论列表(0)

  1. 暂无评论