CRED plugin allows you to build front-end forms for creating and editing content. These forms can include all the fields that belong to the content and display them with your HTML styling. CRED forms also support input validation and automatic email notifications.
When you ask for help or report issues, make sure to tell us the structure and the settings of your form.
Viewing 15 topics - 451 through 465 (of 583 total)
Problem: I have a repeating custom field in a custom post type. When submitting a Form that creates this custom post type, I would like to create a cloned post that copies the values from the repeating custom field and inserts them automatically in the post clone.
Solution: Use wp_insert_post in a cred_save_data hook to create a clone of the original post. Get the repeating field value from the $_POST superglobal, and loop over those values in a foreach loop, or other similar loop structure. Use add_post_meta to insert each value into the custom field in the cloned post.
add_action('cred_save_data', 'my_save_data_action',10,2);
function my_save_data_action($post_id, $form_data) {
$forms = array( 123 );
if ( in_array( $form_data['id'], $forms ) )
{
$gallery = $_POST['wpcf-fieldslug'];
$new_book_args = array(
'post_title' => 'cloned book test from ' . $post_id,
'post_status' => 'publish',
'post_type' => 'book'
);
// Insert the cloned post into the database
$new_book_id = wp_insert_post( $new_book_args );
foreach( $gallery as $img ){
add_post_meta($new_book_id, 'wpcf-fieldslug', $img, false);
}
}
}