CF/7 to custom post, but only for specific form
-
Hey friends,
I created a plugin, that adds the ability to save form data to a custom post type. Looks like this:
<?php function save_posted_data( $posted_data ) { $form_id = $contact_form->id(); if( $form_id == 1903 ) { $args = array( 'post_type' => 'np-food', 'post_status'=>'draft', 'post_title'=>$posted_data['food-name'], 'post_content'=>$posted_data['food-desc'], ); $post_id = wp_insert_post($args); if(!is_wp_error($post_id)){ if( isset($posted_data['food-name']) ){ update_post_meta($post_id, 'food-name', $posted_data['food-name']); } // and so on return $posted_data; } } } add_filter( 'wpcf7_posted_data', 'save_posted_data' ); ?>
That works pretty good when using the form ID 1903. But I when I use any other form, sending the form via submit button ends up in a loop.
How can I force CF7 only to save post data when a specific form is used and just react as normal, when another ID is used?
Viewing 5 replies - 1 through 5 (of 5 total)
Viewing 5 replies - 1 through 5 (of 5 total)
- The topic ‘CF/7 to custom post, but only for specific form’ is closed to new replies.