August 13, 2019 at 5:22 pm #9483
I have a page where I want to embed a front end form. This will be unique to a user and users should only edit their own page/forms.
Ideally I want to set the CPT post ID.
When I use the code below with the URL http://../forms/sample/?_post[ID]=364 all works as expected, it updates the existing CPT.
<?php /* Title: Post Submit Method: post Message: Saved Logged in: true */ // Where to save this form piklist('field', array( 'type' => 'hidden' ,'scope' => 'post' ,'field' => 'post_type' ,'value' => 'cpt1' )); piklist('field', array( 'type' => 'select' ,'field' => 'cpt1_field1' ,'label' => 'Field1' ,'scope' => 'post_meta' ,'attributes' => array( 'class' => 'text' ) ,'choices' => array( '1' => 'Option1', '2' => 'Option2', '3' => 'Option3', '4' => 'Option4' ) )); // Submit button piklist('field', array( 'type' => 'submit' ,'field' => 'submit' ,'value' => 'Submit' )); ?>
What I really want is for the form to load when a user visits http://../forms/sample/
$post = get_post(374); setup_postdata( $post );
but I assume that other code for the form runs before this. Is there a way to set the post id in the code rather than the URL?
August 13, 2019 at 6:24 pm #9484
Solved it. I just cheat and set the global $_Request variable and then use do_shortcode
$_Request['_post']['ID'] = 374; do_shortcode('[piklist_form form="sample" add_on="sample-plugin"]');
August 19, 2019 at 5:07 pm #9490
You could also pass
['_post']['ID']as a query parameter in the url
The topic ‘Update CPT Front End Form without ?_post[ID]=’ is closed to new replies.