• Hello, i d like to learn how to set a default featured image for custom post type, it should be automaticly inserted if while creating new post i don t select any image. i want to avoid posting stuff without featuring image, and i do not always have time to search for custom image for each post.
    i know that taxonomy images can do it for categories, but i do not have any categories in my custom post type.

    i found this code

    function auto_ikona() {
              global $post;
              $already_has_thumb = has_post_thumbnail($post->ID);
                  if (!$already_has_thumb)  {
                  $attached_image = get_children( "post_parent=$post->ID&post_type=attachment&post_mime_type=image&numberposts=1" );
                              if ($attached_image) {
                                    foreach ($attached_image as $attachment_id => $attachment) {
                                    set_post_thumbnail($post->ID, $attachment_id);
                                    }
                               }
                            }
          }
    add_action('the_post', 'auto_ikona');
    add_action('save_post', 'auto_ikona');
    add_action('draft_to_publish', 'auto_ikona');
    add_action('new_to_publish', 'auto_ikona');
    add_action('pending_to_publish', 'auto_ikona');
    add_action('future_to_publish', 'auto_ikona');

    this is for regular posts, how to make it works with custom post type?

  • The topic ‘automaitc featured image’ is closed to new replies.