Advertisement
Guest User

Untitled

a guest
Jun 12th, 2012
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. function autoset_featured() {
  2. global $post;
  3. $already_has_thumb = has_post_thumbnail($post->ID);
  4. if (!$already_has_thumb) {
  5. $attached_image = get_children( "post_parent=$post->ID&post_type=attachment&post_mime_type=image&numberposts=1" );
  6. if ($attached_image) {
  7. foreach ($attached_image as $attachment_id => $attachment) {
  8. set_post_thumbnail($post->ID, $attachment_id);
  9. }
  10. }
  11. $oldField = get_post_meta($post->ID, ‘thumbnail’, true);
  12. if ( !empty ( $oldField ) ) { set_post_thumbnail($post->ID, $oldField); }
  13. }
  14. } //end function
  15. add_action('the_post', 'autoset_featured');
  16. add_action('save_post', 'autoset_featured');
  17. add_action('draft_to_publish', 'autoset_featured');
  18. add_action('new_to_publish', 'autoset_featured');
  19. add_action('pending_to_publish', 'autoset_featured');
  20. add_action('future_to_publish', 'autoset_featured');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement