Get related /connecetd Term Name inside a Group

Support General Get related /connecetd Term Name inside a GroupResolved

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #43596
    Timo WesselsTimo Wessels
    Participant

    I have a custom post type : drink recipes.
    Inside there is a custom field group.

    <div>
    <?php
    $groups = rwmb_meta( 'detailed_ingredients_ingredients_group' );
    foreach ( $groups as $group ) {
    	
    	// Field amount_text:
    	echo $group[ 'amount_text' ] ?? '';
    	
    	// Field unit_ta:
    	$term_id = $group[ 'unit_ta' ] ?? 0;
    	$term = get_term( $term_id );
    	?>
    	<p><a>"><?= $term->name ?></a></p>
    	<?php
    	
    	// Field ingredient_ta:
    	$term_id = $group[ 'ingredient_ta' ] ?? 0;
    	$term = get_term( $term_id );
    	?>
    	<p><a>"><?= $term->name ?></a></p>
    	<?php
    
    }
    ?>
    </div>

    If i choose // Field ingredient_ta: $term_id = $group[ 'ingredient_ta' ] and select a term, i would like to show the related or connected term, with the current choosen one.

    Like i choose for example Vodka Brand Name 1 = ingredient_ta,
    and with either a relationsship or a custom field connected to a term (taxonomy = beverage-category). I would like do display the Vodka Category. Somehow i could not find a way trough it.

    #43601
    PeterPeter
    Moderator

    Hello,

    How do you set the relation between terms on your site? If you use the MB Relationships plugin, you can follow the documentation to get the related/connected term https://docs.metabox.io/extensions/mb-relationships/#terms

    #44175
    Timo WesselsTimo Wessels
    Participant

    Just wanted to give an update how i solved my proplem.
    I combined now several taxonomies into one big hierarichal. And you could choose the terms inside a cloneable group.

    My target was inside a bricks query loop to get the taxonomy advanced parent term name.

    <?php
    
    function mbg_get_ingredient_parent() {
        $obj = Bricks\Query::get_loop_object();
    
        $term = get_term_by( 'id', $obj['detailed_ingredients_ingredient_ta'], 'beverage-category' );
    
        $parent_term_id = wp_get_term_taxonomy_parent_id( $term->term_id, 'beverage-category' );
    
        return get_term( $parent_term_id )->name;
    }

    This code I was putting it via WPCodeBox, always on page load. And in my bricks query i was using {echo:mbg_get_ingredient_parent} to get the result.

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