We are using WordPress wp_insert_post() to make a post in our theme programmatically and then we try to add the values for our custom fields with rwmb_set_meta(), but after the post is created the values for the custom fields is not assigned to the actual post, but on a refresh if i try to insert them with the same logic it does work, i tried to var_dump the new created post and it is created and is available immediately but metabox still doens't assign the value to the fields, below you can find code snippets about the flow of the insertion.
We create the post:
$newWinnerId = wp_insert_post(array (
'post_type' => 'winner',
'post_title' => $competitionName." #".$competitionRoundId,
'post_content' => '',
'post_status' => 'publish',
));
We check if the post exists:
if ($newWinnerId) {
We try to populate the fields with the correct values:
rwmb_set_meta( $newWinnerId, "competition", $wpCompetition->posts[0]->ID);
rwmb_set_meta( $newWinnerId, "end_date", $winTime);
Why would the function not work immediately after post creation?
P.S: i tried to set the table name on the rwmb_set_meta, but not changes and also tried to insert it inside the rwmb_after_post_save action but no luck, and the logic is run inside a add_action('wp', funtion(){});