Support Forum
Support › MB Relationships › Can't display values from relationship
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.
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.
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',
],
],
] );
}
Hi,
Please share your site credentials via this contact form https://metabox.io/contact/
I will take a closer look.