Updating a custom post type post using rwmb_set_meta with a custom table

Support MB Custom Table Updating a custom post type post using rwmb_set_meta with a custom table

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #35225
    MikeMike
    Participant

    When using rwmb_set_meta, it updates the meta value, but it is not saving the value (so the old value is still in the DB).

    Based on Meta Box documentation, although it is really unclear re. the add_action, it suggested that this would save the value.

    I have tried this (with the correct values and also by manually adding test values):

    1) rwmb_set_meta( $object_id, $field_id, $value, $args = [] );

    and also:

    2) add_action( 'init', function() {
    $post_id = 123;
    $field_id = 'my_field';
    $value = 'My custom value';
    rwmb_set_meta( $post_id, $field_id, $value );
    }, 99 );

    Neither updated the db. 1) did update the object until page refresh, 2) did nothing.

    Question is, what do I need to do to update the Meta Box value in the db?

    Again, the documentation really needs to be updated here. I think it would be great to get some of the information in this forum in the documentation.

    #35242
    Long NguyenLong Nguyen
    Moderator

    Hi Mike,

    Did you try to use the example code to update the field value stored in the custom table?
    https://docs.metabox.io/rwmb-set-meta/#examples

    add_action( 'init', function() {
    	$table_name = 'my_table';
    	$post_id = 123;
    	$field_id = 'my_field';
    	$value = 'My custom value';
    	rwmb_set_meta( $post_id, $field_id, $value, [
    		'storage_type' => 'custom_table',
    		'table'        => $table_name,
    	] );
    }, 99 );

    You can also use the public API of MB Custom Table to update field value as well.
    https://docs.metabox.io/extensions/mb-custom-table/#api

    $data = [
    	'field_1' => 'value 1',
    	'field_2' => 'value 2',
    	'field 3' => ['one', 'two', 'three'],
    ];
    \MetaBox\CustomTable\API::update( $object_id, $table, $data );
Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.