Term to Term connections?

Support MB Relationships Term to Term connections?Resolved

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #18843
    MattTaylorMattTaylor
    Participant

    How do I make teen to term connections, when both terms belong to different taxonomies? Nothing I try here works. :/ Thank you!!!!

    #18844
    MattTaylorMattTaylor
    Participant

    ... New Siri autocorrect is a real hassle. 🙂

    #18849
    Long NguyenLong Nguyen
    Moderator

    Hi Matt,

    You can create a relationship between terms easy with this code

    add_action( 'mb_relationships_init', function () {
        MB_Relationships_API::register( [
            'id'   => 'term_to_term',
            'from' => [
                'object_type' => 'term',
                'taxonomy'    => 'category',
            ],
            'to'   => [
                'object_type' => 'term',
                'taxonomy'    => 'product_cat',
            ],
        ] );
    } );

    an example between the category of post and product category of Product (WooCommerce). Then this code will show the terms which are related

    $args = array(
        'taxonomy' => 'product_cat',
        'relationship' => [
            'id'   => 'term_to_term',
            'from' => get_queried_object_id(), // You can pass object ID or full object
        ],
    );
    $terms = get_terms( $args );
    
    foreach ( $terms as $term ) {
        echo $term->name . '<br>';
    }

    To manipulate with the terms, please follow this documentation.

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