Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I've added my own function to save_post as follows:

add_action( 'save_post', 'save_recipe' );

function save_recipe( $post_id ) {
    // ... set $thumb_id from custom code ...

    set_post_thumbnail($post_id, $thumb_id);
}

Now if I check my DB, nothing is set for the field _thumbnail_id inside the wp_postmeta table.

The Strange thing is if I use a die() function right after set_post_thumbnail, and check the DB my line was entered into the DB, so it is like some built in code from wordpress (or my theme) that is stripping it out after the fact.

Any ideas? I assume it has something to do with the featured image code that gets added when you use add_theme_support( 'post-thumbnails' ); in your functions.php.

I should note I'm using Wordpress 3.4.1 as a Network, in addition to using the Thesis 1.8.5 theme which may be adding some complexity.

Also I know I could be using the built in featured post section, but I'm coding this so that I can use identical functions from the front end to add new posts (with a set featured image that the user uploads).

Thanks!

share|improve this question
    
Are you trying to set the Post Thumbnail (i.e. the core post-thumbnail/featured-image functionality), or are you trying to set a custom post meta field? –  Chip Bennett Aug 27 '12 at 16:59
    
I was trying to set the Core post-thumbnail. I found my issue. I was running the function: delete_post_meta($post_id, '_thumbnail_id'), before I would set_post_thumbnail($post_id,$thumb_id); Apparently even though the delete was in the code before it still caused it to delete it from the DB. Very strange... I had it in there as I was worried I would be creating multiple _thumbnail_id meta entries for the same post. –  SgtSlaughter Aug 27 '12 at 17:06
    
Please post that as an answer, along with the entire, relevant code. :) –  Chip Bennett Aug 27 '12 at 17:10
    
I will, thanks (although because my low reputation I have to wait 8 hrs... ugh). –  SgtSlaughter Aug 27 '12 at 17:11
add comment

1 Answer 1

up vote 0 down vote accepted

I was trying to set the Core post-thumbnail. I found my issue. I was running the function: delete_post_meta($post_id, '_thumbnail_id'), before I would set_post_thumbnail($post_id,$thumb_id); Apparently even though the delete was in the code before it still caused it to delete it from the DB. Very strange... I had it in there as I was worried I would be creating multiple _thumbnail_id meta entries for the same post.

share|improve this answer
    
Please use the WYSIWYG editor when posting. Thanks. –  kaiser Aug 31 '12 at 0:54
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.