Skip Navigation

[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.

You can find the proposed solution in this case with the following reply:
=> https://toolset.com/forums/topic/i-would-like-to-display-related-bookscpt-of-on-each-book-single-post/#post-1370013

Relevant Documentation:
=> https://toolset.com/documentation/post-relationships/how-to-display-related-posts-with-toolset/

This support ticket is created 5 years, 6 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 13 replies, has 2 voices.

Last updated by yusukeN-2 5 years, 6 months ago.

Assisted by: Minesh.

Author
Posts
#1369645

Hi, my name is Yusuke.

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.

Thank you in advance.

#1369825

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

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?

#1369875

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.

#1369935

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Great - thanks for the information.

Is it possible to send me wp-admin access details? If yes, I've set next reply as private.

#1369967

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

I don't know why but I see the following error message when I try to load the wp-admin:

403 Error
現在、このページへのアクセスは禁止されています。
サイト管理者の方はページの権限設定等が適切かご確認ください。

#1369977

I edited password below. Can you try again?

#1369983

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Its not about password yet - the wp-admin page it not loading at all so that I can input username and password: hidden link

All I can see is white page with 403 error.

#1369989

Dear Minesh
Sorry, I don’t know “Attack guard” is running. I make it deactivate, please try again.

#1370013

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Can you please check now: hidden link

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:

  [wpv-view name="related-books-to-author" wpvrelatedto="[wpv-post-id item="@book-bookauthor.child"]"] 

=> 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

[wpv-view name="display-related-author-books"]
#1370499

Dear Minesh,

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]

    Please tell me what to do.

  • #1370507

    Minesh
    Supporter

    Languages: English (English )

    Timezone: Asia/Kolkata (GMT+05:30)

    Yes - thats correct.

    I've added those shortcodes to the "related-books-to-author" view's loop editor as given under:

    [types field="book-shoei"][/types]
    [types field="book-title"][/types]
    

    And view gets saved.

    #1371199

    Hi, Mr.Minesh.

    I have confirmed it just now. Thanks to your kind response, I was able to solve it. Thank you very much.

    #1371205

    Minesh
    Supporter

    Languages: English (English )

    Timezone: Asia/Kolkata (GMT+05:30)

    Glad to help. Please feel free to mark resolved this ticket.

    #1371207

    Thank you!!!