[Resolved] I would like to display related books(CPT) of on each book single post.
This thread is resolved. Here is a description of the problem and solution.
Problem:
How to display related posts on single post with many to many post relationships.
Solution:
You need to use the nested view where one view should query the intermediary post type of your many-to-many relationship and it will find the related authors based on the current post and another view should query the post type for which you want to display the related posts.
I am currently creating a website for a publisher. Since it is a publisher's website, it has a database of many books with the following items: For example,
・ Book title
・ Book authors (multiple)
・ ISBN (JAN code) = Also slug
I have already made most of the website. Top page, book list page (archive page), book details page ... But there is one thing I can't accomplish. It is a list of related books to be posted on the book detail page. I want to list books written by the same author.
Here is an example.
There is a detailed page of “The Adventures of Tom Sawyer”. The author is Mark Twain, you know. I want to display a list of all the books written by Mark Twain on the details page of "The Adventures of Tom Sawyer". Of course, I know that only books that are registered in the database can be displayed. For example, “The Prince and the Pauper”, “Adventures of Huckleberry Finn”, “The Mysterious Stranger”. I want to display these three books.
I made two CPTs. "Book" and "Author". I was able to link the two using "Post relationship". On the book registration screen, we registered not only the original author Mark Twain but also Yoko Arima, a Japanese actor. And I was able to display their names using View. All OK until here.
But how do I display related books? I want “Book” single page to display “Book” related to “Author”. I don't know what to do.
In fact, I want to display related books in a simpler way. If I enter up to four ISBNs (unique codes, which are also applied to post slug) of related books on the book registration screen, the images and titles of those books are displayed in a horizontal row. I want you to teach me how to do that.
Hello. Thank you for contacting the Toolset support.
I would first like to know you can assign multiple authors to one book, if this is correct then you should have one-to-many relationship created between your post type book and authors - correct?
Now, if above information is correct, lets say you have "Book 1" where author is assigned "A","B","C" that means when you load the single post of "Book 1" you want to display all books belongs to authors "A","B","C" - correct?
Dear Mr. Minesh,
Thank you for your quick reply. I have already created a relationship between your "Book 1" and multiple authors A, B, and C. However, instead of what you say "one to many", I created "many to many". This is because "Author A" may have written not only Book1, but also Book 2, Book 3, "Author B" may have written Book 4, and "Author C" may have written many more books.
I don't know why but I see the following error message when I try to load the wp-admin:
403 Error
現在、このページへのアクセスは禁止されています。
サイト管理者の方はページの権限設定等が適切かご確認ください。
I've added the following views:
=> hidden link
---- This view query the intermediary post type of your many-to-many relationship and it will find the related authors based on the current book post.
--- To this view's loop editor we added the view with ID 4632:
=> hidden link
----- This view will query the Book post type and display the books related to authors passed as view's shortcode attribute and this view is nested view that is added to view's loop editor of view ID 4631 (query the intermediary post type of your many-to-many relationship) above
- You should check what filters added to view and how Loop Editor is configured for both the views.
To your layout - I've added the following view:
=> hidden link
Thank you for coding. I confirmed two views and their display. Currently only the title of the book is displayed, but I want to display the book image (slug "book-shoei"). In that case, should I edit the loop editor of the "related-books-to-author" view?
<wpv-loop>
[wpv-post-link] </ li>
</ wpv-loop>
I want to add the following field, but I get an error message.
[types field = 'book-shoei'] [/ types]
[types field = 'book-title'] [/ types]