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 - 466 through 480 (of 719 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);
}
}
}
Problem: I have a Form that is used to create child post in a one-to-many post relationship. I would like to get the value of a custom field from the related parent post in a cred_save_data callback, but it does not seem to be working.
Solution: The relationship is not yet set in a cred_save_data hook, so you can either use the cred_submit_complete hook instead, or access the parent post ID directly from the parent select field in the $_POST superglobal.