Display RelationShip Title

Support MB Relationships Display RelationShip Title

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #43101
    JoeJoe
    Participant

    I am using this code to display the relationship on a single post page

    $connected = new WP_Query( [
        'relationship' => [
            'id'   => 'opinion-course', // Use the correct relationship ID
            'from' => get_the_ID(),        // You can pass object ID or full object
        ],
        'nopaging'     => true,
    ] );
    
    while ( $connected->have_posts() ) : $connected->the_post();
        ?>
        <?php the_title(); ?>
                <?php
                $image = rwmb_meta( 'opinion_logo', [ 'size' => 'thumbnail' ] );
                echo '<img loading="lazy" src="' . $image['url'] . '" style="max-height: 80px;">';
                ?>
        <?php
    endwhile;
    
    wp_reset_postdata();
    

    how can I display the name of the connected product ? I know we are on the single product page, which means the product name is the connected product, how can I display the name this product inside my query ?
    reason is -> i need the name for tippy mouse over

    #43107
    PeterPeter
    Moderator

    Hello Joe,

    If you are on the single product page, you can use the function get_the_title() to get the current product title, assign it to a variable and output it in your code. For example:

    $current_product_title = get_the_title();
    $connected = new WP_Query( [ ] );
    ...
    
Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.