Custom Fields
Re-Envisioned
Support MB Custom Table rwmb_set_meta for custom table

  • Creator
    Topic
  • #24691
    Resolved Michael
    Participant

    Hi,

    I am hooking into a function of the wp all import-plugin to readout data from a serialized regular custom field and move it over to a metabox-field, which is in a custom table. this is my code to loop through the various fields:

     
        $data = get_post_meta( $postid, 'all_data', true);
    
    $fields = [
            'address',
            'city',
            'zip',
            'state',
            'email',
            'url',
            'phone'
        ];
    
        // Loop through data
        foreach( $fields as $field ) {
            if( array_key_exists( $field, $data ) ) {
                rwmb_set_meta(
                    $postid,
                    $field,
                    sanitize_text_field( $data[$field] )
                );
            }
        }
    

    If I push data to error_log I can see all the necessary data. However, rwmb_set_meta does not save anything. My custom table is empty 🙁

    What do I do wrong?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Author
    Replies
  • #24694
    Long Nguyen
    Moderator

    Hi,

    The helper function rwmb_set_meta() has not worked with the field which saved value in the custom table yet, only the default table wp_postmeta of WordPress.

    I'm going to inform the development team to cover this case in future updates. Thank you.

    #24696
    Michael
    Participant

    Hi,

    Thanks for the quick answer. So... how do I save my fields in the custom table then? Would this really be a direct call to $wpdb?

    Thanks,
    Michael

    #24720
    Long Nguyen
    Moderator

    Hi,

    Yes, for now, please use the class $wpdb to update the field value in the custom table.
    https://developer.wordpress.org/reference/classes/wpdb/

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