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 badges2 Answers
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
版权声明:本文标题:Save ACF with a save button on a post 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745580770a2664608.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论