get_term_meta vs rwmb_meta

Support MB Term Meta get_term_meta vs rwmb_metaResolved

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #39621
    brandonjpbrandonjp
    Participant
    // retrieve the user id from the related term
    $value = rwmb_meta( 'pm_related_user', ['object_type' => 'term'], $pm_term_id );
    echo $value;// returns ''
            
    $meta = get_term_meta( $pm_term_id, 'pm_related_user', true ); 
    echo $meta; // returns 8
    

    Based on the docs here: https://docs.metabox.io/extensions/mb-term-meta/#getting-field-value
    I expected to both $value & $meta to return the same.

    Any idea why get_term_meta works but rwmb_meta does not?

    I'm using MB Term Meta * Version: 1.2.10

    #39648
    PeterPeter
    Moderator

    Hello,

    The value return from rwmb_meta() could be an array and you cannot echo an array, you should use a for loop to iterate elements and echo it. Please use the var_dump() function to know what the type of $value variable is.

    #39660
    brandonjpbrandonjp
    Participant

    hmmm... var_dump($value) from the above code is showing bool(false)

    #39688
    PeterPeter
    Moderator

    Hello,

    Can you please share the code that creates the custom field on your site? And share some screenshots of the field value in the database?

    #39701
    brandonjpbrandonjp
    Participant

    Hi Peter. Thanks for the reply. Truthfully this is not a big issue for me now, as I have it working using get_term_meta() but I am still curious why rwmb_meta() does not work.

    Below is the code used to create user select meta field on the taxonomy: https://cln.sh/QO9iJ6

    array(
        'id'         => $prefix . 'pm_related_user',
        'type'       => 'user',
        'name'       => esc_html__('User Account', 'text-domain'),
        'desc'       => esc_html__('Select the User Account for this PM.', 'text-domain'),
        'class'      => 'add-add-new',
        'query_args' => array(
            'role__in' => 'c_____project_manager',
        ),
        'field_type' => 'select_advanced',
        'tab'        => 'pm-tab',
    ),

    Here are some samples of the database where the user ID is correctly saving to the meta field pm_related_user - https://cln.sh/4uPNJ3

    Thanks, Peter!
    --Brandon

    #39761
    PeterPeter
    Moderator

    Hello,

    I do not see the issue on my demo site when using the helper function rwmb_meta() to get the term meta. Can you please update the plugin MB Term Meta to the latest version 1.2.10 and check this issue again? If you are using the older version (below 1.1), you can use the WordPress function get_term_meta() only.

    #39762
    brandonjpbrandonjp
    Participant

    I'm using MB Term Meta * Version: 1.2.10

    Thanks for looking into it. But no problem, I’ll just stick with get_term_meta

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