Can't display values from relationship

Support MB Relationships Can't display values from relationship

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #37149
    vacdkvacdk
    Participant

    Hi
    I'm tried like a madness to figure out how to display relationship fields.
    I have tried any compination from the documentation, and i'm just so lost.

    I have created a term for products: venues

    I have created a relationship with code:
    Its to be able to add the terms in the users metadata.

    function your_prefix_function_name() {
        MB_Relationships_API::register( [
            'id'   => 'venue-to-user',
            'from' => [
                'object_type' => 'term',
                'taxonomy'    => 'venues',
                'meta_box'    => [
                    'title' => 'From title',
                ],
                'field'       => [
                    'name'      => 'from label',
                    'max_clone' => '1',
                ],
            ],
            'to'   => [
                'object_type' => 'user',
                'post_type'   => 'post',
                'taxonomy'    => 'category',
                'meta_box'    => [
                    'title' => 'To title',
                ],
                'field'       => [
                    'name'      => 'To label',
                    'max_clone' => '1',
                ],
            ],
        ] );
    }

    I try to output it like the documentation says:

    $terms  = get_terms( [
        'taxonomy'     => 'venues',
        'hide_empty'   => false,
        'relationship' => [
            'id' => 'venue-to-user',
            'to' => 1, // <--user ID
        ],
    ] );
    foreach ( $terms as $term ) {
        print_r($term);
    }

    But i'm getting this output:
    Array ( [invalid_taxonomy] => Array ( [0] => Invalid taxonomy. ) ) Array ( )

    I want to have a cpt or taxonomy that can be related to a user and then output the data on the checkout page.
    Adding it to the checkout page is not the problem, but output the relationship field is.

    #37164
    Long NguyenLong Nguyen
    Moderator

    Hi,

    Please update the hyphen in the relationship ID by underscore characters venue_to_user and re-check this issue. Let me know how it goes.

    #37182
    vacdkvacdk
    Participant

    Didn't go well, nothing works 🙁

    $terms  = get_terms( [
        'taxonomy'     => 'venues',
        'hide_empty'   => false,
        'relationship' => [
            'id' => 'venue_to_user',
            'to' => 1, // User-ID
        ],
    ] );
    foreach ( $terms as $term ) {
        print_r($term);
    }
    add_action( 'mb_relationships_init', 'your_prefix_function_name' );
    
    function your_prefix_function_name() {
        MB_Relationships_API::register( [
            'id'   => 'venue_to_user',
            'from' => [
                'object_type' => 'term',
                'taxonomy'    => 'venues',
                'meta_box'    => [
                    'title' => 'From title',
                ],
                'field'       => [
                    'name' => 'From label2',
                ],
            ],
            'to'   => [
                'object_type' => 'user',
                'post_type'   => 'post',
                'taxonomy'    => 'category',
                'meta_box'    => [
                    'title' => 'To title',
                ],
                'field'       => [
                    'name' => 'To label2',
                ],
            ],
        ] );
    }
    #37202
    Long NguyenLong Nguyen
    Moderator

    Hi,

    Please share your site credentials via this contact form https://metabox.io/contact/
    I will take a closer look.

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