Support

Account

Home Forums ACF PRO Set Post ID via URL parameter or query_var on front end form 'return'

Solved

Set Post ID via URL parameter or query_var on front end form 'return'

  • Hi there,

    I’m using acf_form() to show a form that creates a custom post type on the front end. After this form submits, I want to send the user to a URL with either a query_var or url parameter via the 'return' option.

    Here’s my code, but the $post_id is not passing through…

    	'post_id'			=> 'new_post',
    	'post_title'		=> true,
    	'new_post'			=> array(
    		'post_type'		=> 'my_cpt',
    		'post_status'	=> 'publish',
    	),
    	'field_groups'		=> array(
    		1234
    	),
    	'return'			=> home_url('my-uri/?mycpt_id=' . $post_id),
    	'submit_value' 		=> __("Create CPT", 'acf'),
    	'uploader'			 => 'wp'
    

    Thanks in advance

  • Figured it out

    	function my_save_func($post_id) {
    		
    		
    		$GLOBALS['acf_form']['return'] = home_url('my-uri/?mycpt_id=' . $post_id);
    		
    	}
    	
    	add_action('acf/save_post', 'my_save_func', 20, 1912);
Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘Set Post ID via URL parameter or query_var on front end form 'return'’ is closed to new replies.