I am creating a form with the goal of creating a post and assigning it a feature image. I have the post creation working 100% as expected, but I don't understand why update_post_meta is not functioning as expected.
Here is my code:
if ( $new_post_id = wp_insert_post( array ( "post_title" => $title , "post_content" => $content , 'post_status' => 'publish' ) ) ) {
$result = add_post_meta( $new_post_id , ‘_thumbnail_id’ , 2978 ); // This is to show how both of these don't function as expected
$result2 = update_post_meta( $new_post_id , ‘_thumbnail_id’ , 3013 );
}
Both $result and $result2 have a value, and when I execute: var_dump( get_post_meta( $new_post_id ) ) I get this:
array(1) { [""]=> array(2) { [0]=> string(4) "3013" [1]=> string(4) "2978" } }
It looks like _thumbnail_id does not exist in the meta data, but the values I am trying to add are being saved (separately).
I have also done this: var_dump( get_post_meta( 2960 ) ), on a post I made through this form and manually added a feature image (to test what the id I should use for it is), and I was returned this:
array(3) { ["_edit_lock"]=> array(1) { [0]=> string(13) "1347819627:24" } ["_edit_last"]=> array(1) { [0]=> string(2) "24" } ["_thumbnail_id"]=> array(1) { [0]=> string(4) "2978" } }
Does anyone know of a possible explanation for this behaviour?
_thumbnail_idare curly, just delete and retype them. – jessica Sep 16 '12 at 20:49