rwmb_set_meta() doesn't work after post creation

Support MB Custom Post Type rwmb_set_meta() doesn't work after post creation

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #37334

    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(){});

    #37341
    Long NguyenLong Nguyen
    Moderator

    Hi,

    Can you please share the code that creates the custom fields on your site? If you are using the custom table to save field values, please try to use the API update to update the field value. Read more on the documentation https://docs.metabox.io/extensions/mb-custom-table/#update

    #43288
    Dennis De CockDennis De Cock
    Participant

    we are also experiencing the same issue. A post is created and aftwerwards we assign values to the custom fields. After some updates this is not working anymore. Also: for the posts that were created before the fields are shown below the post and for the newer ones (where no custom fields were assigned) we do not see them on the post page. This is set in the custom fields group.

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.