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?