CRED plugin provides an API, making it easy to customize your post or user forms. The API includes hooks (actions and filters) to accomplish specific tasks using PHP code.
When you ask for help or report issues, make sure to tell us all related information about your form and what you want to achieve.
Viewing 15 topics - 241 through 255 (of 358 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.