WordPress.org

Ready to get started?Download WordPress

Forums

wp insert attachment and thumbs (2 posts)

  1. Neso
    Member
    Posted 2 years ago #

    Hi, I have small problem, my plugin do not create thumbs for my post, it upload image in media library for that post but it not create post thumb (in my media settings I have specified medium thumb 225x225). Also I need that thumb to be featured. Any help?

    This is problematic part of my plugin ...

    $filename = $upload_dir['baseurl'].'/folder/'.$image_name;
    $wp_filetype = wp_check_filetype(basename($filename), null );
    $attachment = array(
    'post_mime_type' => $wp_filetype['type'],
    'post_title' => preg_replace('/\.[^.]+$/', '', basename($filename)),
    'post_content' => '',
    'post_parent' => $post_id,
    'post_type' => 'attachment',
    'post_status' => 'inherit',
    'guid' => $filename,
    );
    $attach_id = wp_insert_attachment( $attachment, $filename, $post_id );
    // you must first include the image.php file
    // for the function wp_generate_attachment_metadata() to work
    require_once(ABSPATH . 'wp-admin/includes/image.php');
    $attach_data =
    wp_generate_attachment_metadata( $attach_id, $filename );
    wp_update_attachment_metadata( $attach_id, $attach_data );
    }
    }
    }

  2. Neso
    Member
    Posted 2 years ago #

    Any help ?

Topic Closed

This topic has been closed to new replies.

About this Topic