Can't display values from relationship
Support › MB Relationships › Can't display values from relationship
- This topic has 3 replies, 2 voices, and was last updated 2 years, 8 months ago by
Long Nguyen.
-
AuthorPosts
-
July 23, 2022 at 9:09 PM #37149
vacdk
ParticipantHi
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.July 24, 2022 at 10:50 PM #37164Long Nguyen
ModeratorHi,
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.July 25, 2022 at 5:46 PM #37182vacdk
ParticipantDidn'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', ], ], ] ); }
July 26, 2022 at 1:07 PM #37202Long Nguyen
ModeratorHi,
Please share your site credentials via this contact form https://metabox.io/contact/
I will take a closer look. -
AuthorPosts
- You must be logged in to reply to this topic.