0

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!

4
  • 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? Commented Aug 27, 2012 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. Commented Aug 27, 2012 at 17:06
  • Please post that as an answer, along with the entire, relevant code. :) Commented Aug 27, 2012 at 17:10
  • I will, thanks (although because my low reputation I have to wait 8 hrs... ugh). Commented Aug 27, 2012 at 17:11

1 Answer 1

0

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.

1
  • Please use the WYSIWYG editor when posting. Thanks.
    – kaiser
    Commented Aug 31, 2012 at 0:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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