How to set post thumbnail in my plugin (3 posts)

  1. Christiann
    Posted 5 years ago #

    I'm making a plugin that uses wp_insert_post() and wp_update_post() to create and edit posts, but I'm not clear on how to set an thumbnail image in my code.

    I'm looking for something like wp_set_post_thumbnail_image($post_ID, $attachment_ID) but of course, that's not quite right.

    Does anyone know how I can do this?


  2. Christiann
    Posted 5 years ago #

    That was pretty easy! I figured it out:

    add_post_meta( $post_id, '_thumbnail_id', $attach_id );

  3. Sisir
    Posted 5 years ago #

    Hi, i know you you figured it out but in wp 3.1 there is a new function called set_post_thumbnail(); The page is appears to be still blank :) But here how you can use it.

    set_post_thumbnail($post_id, $attachment_id);

    The function will return true or false depending on weather it was successful or not.

Topic Closed

This topic has been closed to new replies.

About this Topic