Support

Account

Home Forums Front-end Issues Pass new $post_id to url or… Reply To: Pass new $post_id to url or…

  • Hi @elliot

    EDIT: Okay, I was able to fix it not going to /publish/ but now it’s not adding the query args still. Thanks.

    Thanks for responding to this after almost 2 years. I was in the middle of creating a new service when ACF 5 came out, so I didn’t have issues with implementing it. However, I’m now updating my other site for ACF5 and I’ve ran into this issue with the redirect.

    I’ve tried a few things and I can’t seem to get it to redirect to a) the declared page (in my case, a /publish/ page… I am saving submission as draft and the publish page is for a payment gateway.) and b) with the query args needed to supply the logic to the publish page.

    Any thoughts on this? I’m happy to share my source code. Your plugin has made two pretty large sites successful.

    $args = array(
    							'post_id' => 'new_post',
    							'new_post' => array(
    						        'post_status' => 'draft',
    						        'post_type'  => $cpt,
    						        //'post_title' => 'new listing'
    							),
    							'html_before_fields' => $htmlbefore,
    							'field_groups' => $fieldgroups,
    							'form_attributes' => array('class' => $formattr,'autocomplete' => 'false'),
    							'return' => home_url('publish/'),
    							'submit_value' => 'Submit Listing'
    						);
    
    						acf_form( $args );

    That’s the form.

    And here is one of the pre_save_post functions:

    function my_pre_save_post( $post_id )
    	{
    	    // check if this is to be a new post
    	    if( $post_id != 'new' ) {
    	        return $post_id;
    	    }
    
    	    // Get Post Type
    	    $listing_type = $_POST['acf_form']['bh_post_type'];
    	    $perftype = $_POST['acf_form']['bh_perf_org_type'];
    	 
    	   // Create a new post
    	    $post = array(
    	        'post_status' => 'draft',
    	        'post_type'  => $listing_type,
    	        'post_title' => 'new listing'
    	    );  
    	 
    	   // insert the post
    	    $post_id = wp_insert_post( $post );
    
    	    if ($perftype) {
    	    	update_post_meta( $post_id, 'bh_perf_org_type', $perftype );
    	    }
    
            $query_args = array(
                'pid' => $post_id,
                'step' => 'pick',
                'ptype' => $listing_type,
                'msg' => 'success'
            );
    
            
    
    	    // update $_POST['return']
        	 $_POST['acf_form']['return'] = add_query_arg( $query_args,  $_POST['acf_form']['return'] );
    	 
    	    // return the new ID
    	    return $post_id;
    	}
     
    add_filter('acf/pre_save_post' , 'my_pre_save_post', 10, 1 );

    I know you said $GLOBALS above there and I tried that, but no go, so I went back to $_POST. I didn’t run into this with my other site but it’s also set to return to the same page with just some queries (post is added through a modal).

    Thanks in advance if you notice anything!

    Chris