I'm using PHP automation to create new Wordpress posts (with wp_insert_post). I'm also using 'Simple Fields' to add additional meta fields for displaying on the front end.
My code creates the Wordpress post, keeps the post ID in a variable and then goes on to add the required meta data immediately afterwards.
Trimming all the other clutter, this is my process:
// Insert the post into the database and return the post ID
$post_id = wp_insert_post( $my_post );
// Add '$price' to relevant meta field
update_post_meta($post_id, '_simple_fields_fieldGroupID_1_fieldID_4_numInSet_0', $price);
This works fine, when I check the database, the 'price' meta field has the correct information inserted.
The problems starts when I try to extract it using:
echo simple_fields_value("price", $post->ID);
The code works - But the only way I can get it to pull the data is to log into the Wordpress admin, open the post for editing and then hit 'Update'.
Providing I open every post and hit 'Update', there's not a problem with my code... it does everything as expected.
My question is, what is the 'Update' button doing that I'm not? I've tried using 'wp_update_post' to re-open the post and save after the meta data is added to see if that helped, but it doesn't.
// Open and update post to ensure meta data saves correctly
$update_post = array(
'ID' => $post_id,
'post_title' => $title
);
// Update the post into the database
wp_update_post($update_post);
Your help on this would be much appreciated,