Custom Fields
Support MB User Profile rwmb_my_custom_field_after_save_field can't update my own fields in the database

  • Creator
  • #14264


    I'm using metabox type user with the custom table users.

    I want to use this action:

    add_action( 'rwmb_my_custom_field_A_after_save_field', 'usuario_aprobado_con_codigo_acceso' , 20, 5 );
    function usuario_aprobado_con_codigo_acceso ( $null, $field, $new, $old, $post_id ) {

    Depending of the field my_custom_field_A (the value is in $new), I want to update another custom field of the custom table users, my_custom_field_B

    I see in another posts
    something like this:

    $storage = $field['storage'];
    $storage->update( $post_id, 'last_name', "blablabla" );

    And it run well, it update the filed last_name. It run well with the populate user fields.

    But if I want to update another custom fields that I added in this table, I don't know what I have to do to update the value...
    I try:

    $storage->update( $post_id, 'my_custom_field_B', "blablabla" );

    don't work...
    I try a query:

        global $wpdb;
        $wpdb->update('usuarios', array( 'my_custom_field_B' => 'blablabla'), array( 'ID' => $post_id ) ); 

    and don't work...

    Do you know what I'm doing wrong?


Viewing 2 replies - 1 through 2 (of 2 total)
  • Author
  • #14267
    Anh Tran

    Hi Sergio,

    Did you try:

    add_action( 'rwmb_field_A_after_save_field', function ( $null, $field, $new, $old, $object_id ) {
        $storage = $field['storage'];
        $storage->update( $object_id, 'field_B', 'new value' );
    }, 10, 5 );

    This code works only when the field A is put after field B in the meta box, which means field B is already saved.

    If field A is before field B, then after we run this code, field B still use value from the submission. In this case, please try this code:

    add_action( 'rwmb_field_A_after_save_field', function ( $null, $field, $new, $old, $object_id ) {
        $_POST['field_B'] = 'new value'; // Modify directly submitted value from $_POST.
    }, 10, 5 );

    Yes, I try the first method but don't run.

    But with the second:
    $_POST['field_B'] = 'new value';
    It run well!!!

    Thanks once again.

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