Advertisement
bedas

Untitled

Jul 17th, 2019
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. add_action('cred_submit_complete', 'my_success_action',10,2);
  2.  
  3. function my_success_action($post_id, $form_data){
  4.  
  5. //put whatever control in place to act only on given forms (if cred form ID == etc etc)
  6.  
  7. //get all child posts to the post we created/edited, this is how attachments are bound to their "parent" or owner posts
  8. $args = array(
  9. 'post_parent' => $post_id,
  10. 'post_type' => 'attachment',
  11. );
  12.  
  13. $attachments = get_children( $args );
  14.  
  15. //If there are attachments​, get their ID and update the current post meta _thumbnail_id with it
  16. if ( $attachments ) {
  17. foreach ( $attachments as $attachment ) {
  18. update_post_meta($post_id, '_thumbnail_id', $attachment->ID);
  19. }
  20. }
  21.  
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement