I'm sure this is straightforward but I'm tying myself up in knots here.
It's a library lending system I have two custom post types Items and Loans - when someone borrows a Book a record is created in Loans.
What I need to do is show a count of all Loans for a certain type of Book (the type is a field in the Book type) ideally within a date range (the date is held in Loans)
I think I'm confusing relationships with filters so any guidance would be appreciated.
Hello,
The Book Type field is in Book post type, you can not filter the "Loan" posts by fields of another post type "Book ".
So it needs custom codes, for example:
1) Create a post view:
- Query Loans posts
- Filter by the date field
- Display the Loans post information + post found count:
https://toolset.com/documentation/user-guides/views-shortcodes/#wpv-found-count
2) Use wpv_filter_query filter hook to trigger a custom PHP function, in this PHP function:
a) Get Book post IDs by book type parameter:
https://developer.wordpress.org/reference/classes/wp_query/#custom-field-post-meta-parameters
b) Use above Book post IDs to get all related Loan post IDs:
https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_get_related_posts
c) Pass above Loan post IDs to View's query as parameter "post__in":
https://developer.wordpress.org/reference/classes/wp_query/#post-page-parameters
More help:
https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query