MB_Relationships_API::each_connected Returns Empty Array

Support MB Relationships MB_Relationships_API::each_connected Returns Empty ArrayResolved

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #18904
    Virginie CarmichaelVirginie Carmichael
    Participant

    Hi!

    I'm not sure what I'm doing wrong. I've been on this for a couple of days and can't seem to get the API to return anything. Here's what I have.

    I registered a relationship between Books (CPT) and Authors (CPT)

    add_action( 'mb_relationships_init', function() {
        // Add CPT Relationship between Authors + Books
        MB_Relationships_API::register( [
            'id'   => 'books_to_book_author',
            'from' => [
                'object_type' => 'post',
                'post_type' => 'book',
                'meta_box'    => [
                    'title' => 'Author',
                    'priority' => 'high'
                ],
            ],
            'to'   => [
                'object_type' => 'post',
                'post_type' => 'book-author',
                'meta_box'    => [
                    'title' => 'Books by this author',
                ],
            ]
        ] );
    } );

    On the Book archive page, I want to display the Author(s) name under the book title. I was actually able to do it using a query (like I would do on a single page) but I haven't been able to get it to work with the API.

    When I add this to the archive-book.php page:

    MB_Relationships_API::each_connected( array(
       'id'   => 'books_to_book_author',
      'from' => $wp_query->posts,
    ) );

    And dump the content of $post->connected, this is what it returns: ARRAY (SIZE=0) EMPTY when it for sure has content attached to it. (Like I said, it works if I use the MB_Relationships_API::get_connected, but not MB_Relationships_API::each_connected.)

    Is there something I'm doing wrong?

    #18922
    Long NguyenLong Nguyen
    Moderator

    Hi,

    Thank you for pointing out this bug. We have released a new update to fix it as well, please update the extension MB Relationships or MB AIO plugin then check the function each_connected() again.

    #18931
    Virginie CarmichaelVirginie Carmichael
    Participant

    Hi!

    Thanks for the update!
    I'm getting some content now, but it's not 100% perfect.

    It seems like it finds the author for the oldest book in the archive page and adds that info to the array, but then if the next book also has the same author, it returns empty again. The only time it adds info to the array is on the first time that author name pops up.

    Here's a screenshot of my page: https://share.getcloudapp.com/lluDxEpK

    The oldest book is right, it says "Ginnie Carmichael" as the author. Then all the red square should also say "Ginnie Carmichael" and the yellow one should say two authors, "Ginnie Carmichael" and "Rando Person" (Rando is showing up, but not Ginnie)

    #18959
    Long NguyenLong Nguyen
    Moderator

    Hi,

    We are checking this and will let you know when it has done.

    Thank you and have a nice day.

    #19081
    Virginie CarmichaelVirginie Carmichael
    Participant

    Hi!

    Just checking if there's an update yet?

    Thanks for everything!

    #19090
    Long NguyenLong Nguyen
    Moderator

    Hi,

    A new update has been released, please update MB AIO to the new version 1.11.3 or MB Relationships extension v1.9.2 to check it out.

    Let me know how it goes.

    #19105
    Virginie CarmichaelVirginie Carmichael
    Participant

    Awesome, it's working!
    Thanks for everything 🙂

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