Support

Account

Home Forums ACF PRO acf_form in wp-admin Reply To: acf_form in wp-admin

  • Hi James!

    Thanks for the reply. In this particular case I needed to work around the location rule because I need to hook into acf/save_post …as well, in the backend I need to access only one field and would prefer to render it programmatically instead of having another field group.

    I have gotten the field/form to render in the backend via a metabox and acf_form, however the acf/save_post hook is not being executed. Is this because I should use acf/render_field instead …or because acf_form_head() needs to be added (in which case, how would I do that)?

    Here’s my code:

    
    // Meta Box
    	
    function custom_meta_box_markup(){
    
    	$options = array(
    		'post_id'			=> $cpt_id,
    		'post_title'		=> false,
    		'field_groups'		=> array(
    			1234
    		),
    		'fields' => array(
    			'field_012345678901a',
    			'field_012345678901b',
    		),
    		'updated_message' 	=> $updated_message_text,
    		'submit_value' 		=> $submit_value_text,
    		'uploader'			=> 'wp'
    	);
    
    ?>
    	<div class="my-div">
    		<?php acf_form($options); ?>
    	</div>
    <?php
    }
    
    function add_custom_meta_box(){
    	add_meta_box("demo-meta-box", "My Custom Metabox", "custom_meta_box_markup", "dispute", "normal", "high", null);
    }
    
    add_action("add_meta_boxes", "add_custom_meta_box");
    
    // Action Hook
    function my_save_form($cpt_id) {
    	if(is_admin()){
    		global $post
    		$cpt_id = $post->ID;
    		$my_field = get_field('field_012345678901a',$cpt_id);
    		
    		update_post_meta($cpt_id,'test',$my_field); // This is just an example, but it's not working
    	}
    
    };
    add_action('acf/save_post', 'my_save_form', 20);
    

    Huge thanks in advance!