Hi all, I am not so sure this is the right place to post this, but I have seen similar threads here... This is not through admin but via scripting/coding. I am creating a plugin that will create posts from external data. I have managed to insert posts and post meta, etc, but I haven't yet found out how to add a feature image to the post. I know how the images are saved through the wordpress insert functions but setting posts feature images is what I don't know how. Does anyone know the functions for this task? I can't find it in Wordpress reference. Thanks.
Could sometime give me some tip on how to do this. A link to where I can find some help as well will be useful.
Okay, I have figured how to do this. It is actually very simple but you have to consider other factors. So this won't be a matter of calling the function and it work. All you do is call; set_post_thumbnail( $postid, $post_images_id ); But you have to make sure that the file that has that function is included somewhere. The function looks like this; function set_post_thumbnail( $post, $thumbnail_id ) { $post = get_post( $post ); $thumbnail_id = absint( $thumbnail_id ); if ( $post && $thumbnail_id && get_post( $thumbnail_id ) ) { $thumbnail_html = wp_get_attachment_image( $thumbnail_id, 'thumbnail' ); if ( ! empty( $thumbnail_html ) ) { update_post_meta( $post->ID, '_thumbnail_id', $thumbnail_id ); return true; } } return false; } PHP: I thought I post it here just in case someone will need it some day. Another question if someone would help me. I know when you make a new post wordpress activates all the installed plugins. When I make a new post the plugins do not take effect. For example the wp-to-twitter plugin won't apply. Is there a way to make all the plugins to be active?
I also faced the same problem few months back but I left the project. If anyone know how to do this do share with us.