Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- add_action('cred_submit_complete', 'my_success_action',10,2);
- function my_success_action($post_id, $form_data){
- //put whatever control in place to act only on given forms (if cred form ID == etc etc)
- //get all child posts to the post we created/edited, this is how attachments are bound to their "parent" or owner posts
- $args = array(
- 'post_parent' => $post_id,
- 'post_type' => 'attachment',
- );
- $attachments = get_children( $args );
- //If there are attachments​, get their ID and update the current post meta _thumbnail_id with it
- if ( $attachments ) {
- foreach ( $attachments as $attachment ) {
- update_post_meta($post_id, '_thumbnail_id', $attachment->ID);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement