Home › Toolset Professional Support › [Resolved] Display Categories Within A View That Uses Intermediary Posts
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 20 replies, has 2 voices.
Last updated by chantalM 3 years, 9 months ago.
Assisted by: Minesh.
Hello there,
I have a many-to-many relationship on my site - Venues + Shows + Intermediary Posts (Times / Price)
All the Shows are categorised - eg. Comedy, Action etc
I have approximately 100 Venues and several categories, and I want to be able to display the shows in each category for each venue eg display the Shows that belong to a certain Venue that are in the Comedy category.
I think there are 2 ways to do this:-
Method 1) Create a View of all the Intermediary Posts
And then using the wpv-attribute, I can display all posts marked within a certain category or categories using the shortcode, and I assume any variation I want, just from the one view.
If this is the right way to do it, then please can you break down what I need to do here because I have tried [wp-view name="NAME" category="NAME"] but this doesn't work
I've tried to nest a View inside a View but my attempts have failed. I don't know how to apply this and the documentation is not clear to me.
Method 2) Create View specific to a CPT(Venues) like so:
Content: Intermediary Posts
Query: Select items 'in the Posts Venues relationship' as related 'Posts Venues Intermediary Posts' of Specific: Venues (and then the venue in question eg ABC Building)
This View displays all the posts (shows) that belong to this Venue. Unlike the first idea I would have to create a View for each Venue which is not a problem if this solution works.
So all the films are now showing for a specific venue... how do I display the categories using this method? eg all the posts in the Comedy category showing at this venue
Please can you advise.
Many thanks for your help.
Hello. Thank you for contacting the Toolset support.
The thing is that, what content you would like to display.
If you want to display fields from intermediary post type, then view must set to query the intermediary post type and when you set the view to query the intermediary post type, it will have access to intermediary post type and Venues (parent) and Shows (child).
In your case, it seems Method 2) will be suitable but then you should set your view to query the shows and set a query filter to filter the category like you shared in Method 2).
If you can share admin access details and share a test case example where you want to display what then I will be able to guide you in the right direction.
Please share problem URL and access details and a test case example what category you want to filter.
*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.
I have set the next reply to private which means only you and I have access to it.
I can see the Genres taxonomy is assigned to both venue and shows post types.
As you set the view to query intermediary post type, you can not setup a query filter as you can setup query filer for custom field and taxonomy belongs to the post type you set your view to query. In this case you set the view to query intermediary post type and intermediary post type does not have Genre.
I would like to know what things you would like to display? Do you want to display information from parent+child+intermediary post type? or you want to display information from parent+child?
Also, I see you added post-relationship filter "Select posts in a Posts Venues relationship that are related to ABERDEEN, His Majesty’s Theatre." - Do you want to display parents belongs to this specific post " ABERDEEN, His Majesty’s Theatre"?
Hi Minesh,
Have you read my second post with a detailed explanation I provided along with the login info? I've broken down everything exactly.
I set up the View according to your first response... I need to display intermediary information for a specific Venue (child) (eg Aberdeen, His Majesty’s Theatre) so I added the post-relationship filter, but I also want to display parents belonging to this specific post Aberdeen, His Majesty’s Theatre. The parents are categorised as explained in detail in my post.
At the moment, the View displays all parent posts, and not the ones that are categorised.
How can I get this shortcode to work?
[wpv-view name="aberdeen" wpvgenre="musical"]
What do I need to do to make this work? Thanks.
Yes - I read your reply but you will have to understand when you set your view to query intermediary post type, you can not filter view using taxonomy that is attached.
For instance, you have a post type A and taxonomy B and another post type C and many to many post relationship between post type A and C and it will create one additional post type that will seat between post type A and C, lets name it ACmany2many.
Now, what you have done is you created view using intermediary post type "ACmany2many", but you can not filter this view using taxonomy B as taxonomy B is not attach to post type "ACmany2many".
I hope you got my point.
If you want to filter your view with taxonomy B, you will have to set your view to query post type A as taxonomy B is attached to post type A.
So, I've created the following test view that is set to query the post type "shows" and also added the taxonomy filter Gerne:
=> hidden link
I've created the following demo page where I've added the above view as given under - to filter the view with term "family"
=> hidden link
[wpv-view name="toolset-demo-view" wpvgenre="family"]
I can see if shows the correct results on frontend: hidden link
Yes Minesh, but I need to know display the associated intermediary data like so: hidden link
How do I do this please?
That you will have to adjust within the view's loop editor. Please check the following demo view's Loop editor section:
=> hidden link
I've adjusted the content within the view's loop as given under:
<wpv-loop> <li> [wpv-post-link] </li> <a href="[wpv-post-url]">[wpv-post-featured-image size="custom" width="400"]</a><br> <strong>[wpv-post-title]</strong><br> <strong>[wpv-post-title item="@post-venue.child"]</strong><br> [types field="booking-from" format="D d M " item='@post-venue.intermediary'][/types] - [types field="booking-until" format="D d M Y" item='@post-venue.intermediary'][/types]<br> [types field='no-ticket-text' item='@post-venue.intermediary'][/types] <div class="ticketlink"><strong>[types field='ticket-link' title='BOOK TICKETS NOW' target='_blank' item='@post-venue.intermediary'][/types]</strong></div> </wpv-loop>
I can see the content on the frontend: hidden link
Hi Minesh, thank you SO much for your help.
How would I display the post title of the child (Venue) it belongs to? ie ABERDEEN, Her Majesty's Theatre. At the moment the (wrong) code I am using is displaying the incorrect venues.
For that - I've changed how we added the shortcode to the page:
=> hidden link
[wpv-view name="toolset-demo-view" wpvgenre="family" wpvrelatedto="5064"]
We are passing the " ABERDEEN, Her Majesty's Theatre." post ID with "wpvrelatedto" shortcode attribute.
Within the view, to display the " ABERDEEN, Her Majesty's Theatre." as child we are using the following shortcode in the view:
=> hidden link
<strong>[wpv-post-title item="[wpv-attribute name='wpvrelatedto']"]</strong><br>
Minesh, thank you so, so much.
Just a couple more questions related to this View please and I am all set!
1. I need to order the View by 'Field - Booking From' but when I change this in Ordering from 'Post Date' to 'Field - Booking From' the view disappears. Is there another way of doing this - like adding something to the shortcode?
2. How can I display posts from more two Venues in one View?
So in this example it's Posts 5064 (Aberdeen) and 5065 (Aylesbury)
Can I do something like this? [wpv-view name="toolset-demo-view" wpvrelatedto="5064, 5065"]
1. I need to order the View by 'Field - Booking From' but when I change this in Ordering from 'Post Date' to 'Field - Booking From' the view disappears. Is there another way of doing this - like adding something to the shortcode?
==>
You can not set order by using the intermediary post type custom field as the view is set to query the post type "Show". I already explain you that with my previous reply that you can use the custom fields for filter or order purpose for the fields that belongs to the post type you set your view to query. You can say this is a limitation.
2. How can I display posts from more two Venues in one View?
So in this example it's Posts 5064 (Aberdeen) and 5065 (Aylesbury)
Can I do something like this? [wpv-view name="toolset-demo-view" wpvrelatedto="5064, 5065"]
==>
You can use the following way:
[wpv-view name="toolset-demo-view" wpvrelatedto="5064"] [wpv-view name="toolset-demo-view" wpvrelatedto="5065"]
Hi Minesh, I need it to order by Booking From date hence why I chose Intermediary Posts initially...
I know you said it was a limitation but if I contacted a contractor would they be able to order it via Booking Until using custom code - or is it not possible at all?
Otherwise, using the Intermediary Posts as the query is there any way I can connect it to the Genre? What I have now is perfect but I can't have it ordered by Post Date, I need it ordered by Booking From.
Thanks.
To sort the view based on the booking from date I've added the following filter code to "Custom Code" section offered by Toolset within the "Toolset Custom Code" snippet:
=> hidden link
add_filter( 'wpv_filter_query_post_process', 'func_order_view_basedon_booking_from', 20, 3 ); function func_order_view_basedon_booking_from( $query, $view_settings, $view_id ) { global $wpdb; if ( in_array( $view_id, array( 12025 ) ) ) { if ( !empty( $query->posts ) ) { // if the query found no posts $allposts = $query->posts; foreach($allposts as $k=>$v): $sql = $wpdb->prepare( "SELECT element_id FROM {$wpdb->prefix}toolset_connected_elements WHERE group_id in( select intermediary_id from {$wpdb->prefix}toolset_associations where parent_id=(select group_id from {$wpdb->prefix}toolset_connected_elements where element_id=".$v->ID.") AND child_id=(select group_id from {$wpdb->prefix}toolset_connected_elements where element_id=".$view_settings['post_relationship_id'].") )"); $res = $wpdb->get_results($sql, OBJECT); foreach($res as $x=>$y): $date_array[$v->ID] = get_post_meta($y->element_id,'wpcf-booking-from',true); endforeach; endforeach; } // sorting the array asort($date_array); foreach($date_array as $k=>$v): foreach($allposts as $x=>$y): if($k==$y->ID){ $sorted[] = $y; } endforeach; endforeach; $query->posts = $sorted; } return $query; }
Can you please confirm it works as expected now and sorted correctly:
=> hidden link
Can you please confirm the solution I shared help you to resolve your issue.
Hi Minesh,
Thank you, the code you have used is working on your Demo page and the three posts are in chronological order, but I have noticed a couple of things:
1. The code above is not the same as the code in the Toolset Custom Code Area
2. I want to test your code on the following View - '11832'
You can see it in action on the following page: hidden link
When I replace your View ID 12025 with this ID, the View disappears from the page. How can I apply your code to this View please?
Many thanks.