Support » Plugin: Advanced Forms » My form is working, but problems with taxonomies

  • Resolved moxymore


    Hello there,

    What a nice plugin… I just found it today, it works as expected, but I wonder how I can save/update several custom taxonomies terms which were checked in the form and to be populated in the new post?

    I’m actually at this stage, where the content and title submission is working properly for my custom post type ‘jeux-video’ :

    function generate_post_from_form_submission() {
    	// Get the submitted field values
    	$post_title = af_get_field( 'acf_custom_title' );
    	$post_content = af_get_field( 'acf_custom_content' );
    	// Set up a form using the values for post title and content
    	// Replace post_type with whatever type of post you want to generate
    	$post_data = array(
    		'post_type' => 'jeux-video',
    		'post_status' => 'private',
    		'post_title' => $post_title,
    		'post_content' => $post_content,
    	// Create post with the previously retrieved values
    	$post_id = wp_insert_post( $post_data );
    	// Save extra_information field directly to custom field on post
    	af_save_field( 'extra_information', $post_id );
    add_action( 'af/form/submission/key=form_hiddenFormKey', 'generate_post_from_form_submission', 10 );

    af_save_field isn’t used yet, I’ll do it after understanding how taxonomies works. Can you give me some information on how to save checked terms of a taxonomy called ‘mytax’ please?

    I have probably to get these terms with get_terms/get_the_terms… but I just need an example of how to embed the result in this function.

    Thank you in advance.


Viewing 2 replies - 1 through 2 (of 2 total)
  • I got it! Just use wp_set_post_terms in order to update the tax :

    // Save extra_information on post
        wp_set_post_terms( $post_id, $taxoterms, $taxonomy, false );

    Thank you.

    Plugin Author fabianlindfors


    Sounds like a good solution, nice work!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘My form is working, but problems with taxonomies’ is closed to new replies.