rwmb_meta not returning value for users custom table

Support MB Custom Table rwmb_meta not returning value for users custom table

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #33295
    Nicholas CoxNicholas Cox
    Participant

    Hi

    I found this thread which has the same issue as me but just wondered if there was any update on the issue being fixed? i have tried this on custom post types and user (custom tables) and I cannot return a value. It only works for values which exist in the default postmeta and usermeta tables.

    https://support.metabox.io/topic/rwmb_meta-not-working-for-custom-table/

    $value = rwmb_meta( 'city', ['storage_type' => 'custom_table', 'table' => 'wp_dc_users', 'object_type' => 'user'], 3 );
    var_dump($value);

    Capture

    thanks

    #33301
    Long NguyenLong Nguyen
    Moderator

    Hi Nicholas,

    Where did you use the helper function rwmb_meta() to get the value? I've just added it to the post template and it works well, here is the screen record https://monosnap.com/file/cpPQE3QCCeVAsJhvyoTI6qTwhsuqKX

    #33310
    Nicholas CoxNicholas Cox
    Participant

    Hi Long,

    Ok so I am running this code inside a class within my own plugin (oop structure). I have just realised this is being called too early? If i wrap this code inside wp_loaded it works. I guess I cant use the helper function then as I need this to run before the page loads. Is there any other option? other than direct wpbd calls?

    
    add_action( 'wp_loaded','test' );
    function test() {
        $value = rwmb_meta( 'city', ['storage_type' => 'custom_table', 'table' => 'wp_dc_users', 'object_type' => 'user'], 3 );
        var_dump($value);
    }
    

    I have also tested this inside my theme files and it does load the value correctly.

    #33319
    Long NguyenLong Nguyen
    Moderator

    Hi,

    You need to hook your function to the action init with priority later than 20 or other later hooks to run the helper functions.

    Or you can query directly to the database via the class $wpdb to get the value. Refer to the documentation
    https://developer.wordpress.org/reference/classes/wpdb/
    https://docs.metabox.io/extensions/mb-custom-table/#query-posts-with-wp_query

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