Why doesn't this work when $direction is 'from'?

Support MB Relationships Why doesn't this work when $direction is 'from'?

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #41292
    info@ceescoenen.nl[email protected]
    Participant
    function checkRelation($id, $direction)
    {
        if ($direction == "to") {
        $connected = new WP_Query([
            "relationship" => [
                "id" => $id,
                "to" => get_the_ID(),
            ],
            "nopaging" => true,
        ]);
    } else {
        $connected = new WP_Query([
            "relationship" => [
                "id" => $id,
                "from" => get_the_ID(),
            ],
            "nopaging" => true,
        ]);
    }
    
    $count = $connected->found_posts;
    
    while ($connected->have_posts()):
        $connected->the_post(); ?>
        <a>"><?php the_title(); ?></a>
    <?php
    endwhile;
    
    wp_reset_postdata();
    return "Connected posts/pages: " . $count;
    
    }
    #41305
    PeterPeter
    Moderator

    Hello,

    Can you please give more details about the issue? Please share the code that creates the relationship on your site and an example when you use the function checkRelation().

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