Home › Toolset Professional Support › [Resolved] HELP WITH NESTING VIEWS OF POSTS WITH PARENT-CHILD RELATIONSHIP
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 |
---|---|---|---|---|---|---|
- | 9:00 – 13:00 | 9:00 – 13:00 | 9:00 – 13:00 | 9:00 – 13:00 | 9: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/Karachi (GMT+05:00)
Tagged: Content Templates, Displaying post relationships, Setting up post relationship, Types plugin, Views, Views plugin
Related documentation:
Hello, I have a problem I need help with.
I created a website about a University-based Research Project whose purpose is to find a way to lengthen Tuscan Bread’s shelf life. The project has a 2 years life span, during which researchers are going thru a series of project phases, about which they need to collect a number of multimedia documentation, that could be pdf docs, press reports, videos etc.
So I have created a cpt called PROJECT PHASES that’s parent to MULTIMEDIA FILES, with a relationship one to many. I have also created a taxonomy related to MULTIMEDIA FILES, with a single image custom field that’s the ICON of the multimedia file.
Here is what I would like to do.
I would like to have a view formatted like image n. 1 with PROJECT PHASES that only have child posts (I found the solution in the support system archive for this), with a link to a page with all the MULTIMEDIA FILES pertaining to that PROJECT PHASE formatted like image n. 2
Top solution would be if the “multimedia file photo” could actually be dragged in from the the custom taxonomy field ICON of the taxonomy associated to that multimedia file.
Hi Silvia,
Thank you for contacting us and I'd be happy to assist.
Before suggesting the best way forward, I'll need to make sure that I've understood the requirement clearly.
It is clear that you have two CPTs ( "PROJECT PHASES" & "MULTIMEDIA FILES" ), which are joined through one-to-many post-relationship.
But, I'm not sure I fully understand the role/need of the custom taxonomy attached to the MULTIMEDIA FILES. A custom image for the icon/avatar of a single "MULTIMEDIA FILES" post, can be used from an image custom field attached to this "MULTIMEDIA FILES" CPT directly too.
To start with, your parent view will show the "PROJECT PHASES" posts on a page ( image 1 ).
When a visitor will click on an individual phase, it will lead to that single "PROJECT PHASES" post page. In the content template assigned to this post type, you can add a view to show all "MULTIMEDIA FILES" posts, which are related to the current "PROJECT PHASES" post ( image 2 ).
Here is a useful guide on the topic of showing multiple related posts, through a post view:
https://toolset.com/documentation/post-relationships/how-to-display-related-posts-with-toolset/#displaying-many-related-items
I hope this helps and please let me know if you need any further assistance around this.
regards,
Waqar
If I understood correctly what you are suggesting, I am afraid that it is not the solution I was looking for, and this is probably because I did not explain the problem sufficiently correctly. I'll try to do it.
First of all I'm building this website using OXYGEN BUILDER.
I decided to use an OXYGEN template to show the single post PROJECT PHASE and all the custom fields associated with it.
Due to the incomplete compatibility between OXYGEN and TOOLSET FORMS (see this support ticket for a similar problem from the Toolset site:
https://toolset.com/forums/topic/front-end-content-editing-forms-built-with-cred-embedding-in-elementor-single/?fbclid=IwAR1dc6hgnr0FUL6BqbpHGineVXWLu5V3DeDQ3RHhG5e7CasyUkgJddXyO1c) I am forced to create a TOOLSET custom template to make sure that in the single page of each PROJECT PHASE I can insert the links to MODIFY and DELETE the post from the front end.
The TOOLSET CUSTOM TEMPLATE therefore simply contains this code:
<div class = "row"> <div class = "col-md-3"> [toolset-edit-post-link content_template_slug = 'form-edit-phase' target = '_ self' class = "btn btn-warning"] MODIFY [/ toolset-edit- post-link] </ div> <div class = "col-md-3"> [cred_delete_post_link action = 'trash' redirect = '13 'message =' Do you really want to delete this post? ' message_show = '1' class = 'cred-refresh-after-delete' class = "btn btn-warning"] CANCEL [/ cred_delete_post_link] </div> <div class = "col-md-6"> </div> </div>
Now, I would like the user, by clicking on one of the PROJECT PHASES was taken to a page where the View which lists all the multimedia files related to that PROJECT PHASE is displayed. I suppose you can do it by building the View and passing some parameter to provide parent ID, and that's what I can't do, for which I'm asking for help.
As far as the image of the taxonomy is concerned, this is the reason: each MULTIMEDIA FILE upon being entered must be associated to one of the three taxonomy terms provided, namely ARTICLE, DOCUMENT or VIDEO. Since not every MULTIMEDIA FILE is supposed to have an associated image, and since I don't want to force my client to have to find an image to upload each time in the MULTIMEDIA FILE, in order to make the View results look more homogeneous I created three icons corresponding to the three taxonomy terms and I inserted them as a custom Field of the taxonomy. I would like to show that image as a thumbnail of the MULTIMEDIA FILE.
I hope the problem is clearer now.
Thanks for writing back and for sharing further details.
> Now, I would like the user, by clicking on one of the PROJECT PHASES was taken to a page where the View which lists all the multimedia files related to that PROJECT PHASE is displayed. I suppose you can do it by building the View and passing some parameter to provide parent ID, and that's what I can't do, for which I'm asking for help.
- Since in this case, you'll be on the single PROJECT PHASE page, you won't have to pass on the ID of the parent in the relationship "PROJECT PHASES-MULTIMEDIA FILES".
( as the current page will be the parent )
To get all its related MULTIMEDIA FILES posts, you'll create a post view for this post type and in the "Query Filter" section include a relationship filter, with the option "The post where this view is shown", as can be seen in this screenshot:
https://toolset.com/wp-content/uploads/2018/05/toolset-post-relationship-query-filter.jpg
( source: https://toolset.com/documentation/post-relationships/how-to-display-related-posts-with-toolset/#displaying-many-related-items )
In case this relationship filter doesn't work, you're welcome to share temporary admin login details, along with the information about the view and the content template where you've placed this view.
Note: Your next reply will be private and please make a complete backup copy, before sharing the access details.
As for the use of custom taxonomy and its custom field, yes that makes perfect sense.
I am sorry but evidently I still haven't succeeded in explaining what I want.
>Since in this case, you'll be on the single PROJECT PHASE page, you won't have to pass on the ID of the parent in the relationship "PROJECT PHASES-MULTIMEDIA FILES". ( as the current page will be the parent ).
-No, that's not the starting point. Please take a look at IMAGE-1 in my first post. THAT'S the starting page. A page that displays a view listing ALL project phases that HAVE multimedia files attached. I would like the user to be able to click on the corresponding button that says "view multimedia" and THEN land on a page that lists all MULTIMEDIA FILES for that PROJECT PHASE. Since the landing page does not contain a view I assume the parent id must be passed via the button link in some way, but I haven't found examples that helped me to do so.
>As for the use of custom taxonomy and its custom field, yes that makes perfect sense.
yes but how do I do it?
I think we don't have confusion about how the starting page will work.
The starting page will be a regular page ( example: yourwebsite.com/page-1 ), which will have a post view to show the "PROJECT PHASES" posts.
The difference arises about where would this "view multimedia" button lead to visitor next, i.e. the page 2.
Earlier, I thought you'd want to use individual single "PROJECT PHASES" post pages for this, but now I understand that you don't want to use them for this.
Based on this part of your message:
"I would like the user to be able to click on the corresponding button that says "view multimedia" and THEN land on a page that lists all MULTIMEDIA FILES for that PROJECT PHASE."
If my understanding is correct, you can create a new regular page ( example: yourwebsite.com/page-2 ) and link all your "view multimedia" post buttons from page 1 to this page.
The only difference would be that the ID of each "PROJECT PHASES" post would be passed in the link's URL.
Example of a simple link to page 2:
<a href="<em><u>hidden link</u></em>">view multimedia</a>
Example of a link to page 2, with "PROJECT PHASES" post's ID:
<a href="<em><u>hidden link</u></em>;">view multimedia</a>
Please note how I've used "wpv-post-id" shortcode ( ref: https://toolset.com/documentation/user-guides/views/views-shortcodes/#wpv-post-id ) in the URL parameter, to pass the view's current post.
As a result, when the visitor will reach your page 2 after clicking the specific project phase's link, its ID will be available in the URL parameter for the second view to listen and show MULTIMEDIA FILES only related to that post.
I hope this what you're looking for and I'll strongly recommend sharing the admin access and link to pages that you're working with.
This way I'll be able to see how everything is set up and what's missing, to provide more efficient support.
Yes, that is exactly what I want to achieve. And I have a problem setting the view that will list the multimedia files. I have troubles setting the filter that will allow the view to have the project phase passed via URL. I have created a user for you to take a look. I am sorry the website is in italian, I hope it's not too much trouble. How do I share credentials?
Thanks for the update and glad that we're making progress.
I've set your next reply as private so that you can share the credentials and information about the pages.
And the website's language won't be an issue.
Thank you for sharing the admin access.
I noticed your website is using the view "MULTIMEDIA PER FASE" to show the "Multimedia Files" posts on the page:
yourwebsite.com/archivio-multimedia-files/
But without any relationship filter, it shows all posts from that post type.
To make this view show only posts which are related to "Fasi Progetto" post whose ID has been passed in the URL, I've included a "Query Filter" for this, as shown in this screenshot:
hidden link
As a result, if I pass on ID of a specific "Fasi Progetto" post in the URL parameter "fasi-progetto", it will show only related "Multimedia Files" posts.
Example:
yourwebsite.com/archivio-multimedia-files/?fasi-progetto=752
When you'll visit your page through this link, you'll only see multimedia posts related to "FASE 3" ( ID: 752 ).
I hope this helps.
Waqar, awesome, thank you so much! Setting the view the way you did was the missing step I needed to know about. Now it works perfectly. One last question then.
I have set the multimedia thumbnail to be evaluated via code:
[wpv-conditional if="( CONTAINS(#(tipo-multimedia),'video') )"] <img src="<em><u>hidden link</u></em>" width="75" height="75" class="size-full" /> [/wpv-conditional] [wpv-conditional if="( CONTAINS(#(tipo-multimedia),'Articolo') )"] <img src="<em><u>hidden link</u></em>" width="75" height="75" class="size-full" /> [/wpv-conditional] [wpv-conditional if="( CONTAINS(#(tipo-multimedia),'Documento') )"] <img src="<em><u>hidden link</u></em>" width="75" height="75" class="size-full" /> [/wpv-conditional]
What should I do if I wanted the view to use the Taxonomy ICON (which is a taxonomy term custom field I created) instead?
Thanks for the update and glad that it works.
I couldn't see any taxonomy custom field defined at the moment on your website, but to show the custom field value from it, you can use a nested view.
The new view will be set to show the taxonomy terms "tipo-multimedia", with a query filter to show only terms related to the current post.
( example screenshot: hidden link )
In the content of this view's loop, you can include icon's HTML based on the current term's custom field value and then place this view's shortcode in the loop content template for the parent view ( "MULTIMEDIA PER FASE" ).
HI Waqar thanks again for your help. I realized I had added the taxonomy custom field IMAGE in another website I am working on, that is why you couldn't find it on the website you saw. Now I have added the taxonomy custom field ICON, and I am a bit confused about your comment "you can include icon's HTML based on the current term's custom field value".
Can you help?
Thanks for the update and I apologize for the delay in the reply.
You can get the term's custom field image URL using the Type Field API shortcode:
https://toolset.com/documentation/customizing-sites-using-php/functions/#image
Example:
Image URL for Filmato term (ID: 27): [types termmeta='icona-tm' term_id='27' output='raw'][/types] Image URL for Articolo term (ID: 24): [types termmeta='icona-tm' term_id='24' output='raw'][/types] Image URL for Documento term (ID: 19): [types termmeta='icona-tm' term_id='19' output='raw'][/types]
The code in your view "MULTIMEDIA PER FASE" will become:
<td>[wpv-conditional if="( CONTAINS(#(tipo-multimedia),'Filmato') )"] <img src="[types termmeta='icona-tm' term_id='27' output='raw'][/types]" width="75" height="75" class="size-full" /> [/wpv-conditional] [wpv-conditional if="( CONTAINS(#(tipo-multimedia),'Articolo') )"] <img src="[types termmeta='icona-tm' term_id='24' output='raw'][/types]" width="75" height="75" class="size-full" /> [/wpv-conditional] [wpv-conditional if="( CONTAINS(#(tipo-multimedia),'Documento') )"] <img src="[types termmeta='icona-tm' term_id='19' output='raw'][/types]" width="75" height="75" class="size-full" /> [/wpv-conditional]</td>
I hope this helps and for a new question or a concern, you're welcome to start a new ticket.
Hello Waqar and thanks for answering ... but this is not what I meant. This way I still have to have the wpv-conditional to evaluate what kind of multimedia file it is... what difference does it make whether I output the icon image via <img> tag or taxonomy term? I thought the purpose of a taxonomy term would be to be used directly in the code as I use any other custom field. I wanted to use the taxonomy term because that way I could have gotten rid of all the evaluation code, as the multimedia file has a taxonomy term related to it, and all I have to do is use the custom field related to its taxonomy term the same way I would use any other cpt custom field... It would make sense to me if I could use it like this:
<img src="[types termmeta='icona-tm' output='raw'][/types]" width="75" height="75" class="size-full" />
without having to specify the term-id, as the taxonomy term is already associated with the multimedia file and I should be able to retrieve its custom fields values. I hope I managed to explain myself well enough!
Hi Silvia,
I apologize for the confusion as I thought your question was only directed towards getting the image URL from the term field.
To completely automate this without the need of those conditional blocks, you can create a new taxonomy view to show the only connected "Tipi Multimedia" term.
( in this set up you'll have to make sure that each "Steps Fasi" post always includes only a single "Tipi Multimedia" term )
You can check the example view "View to show icon from Tipi Multimedia" and note how "Limit and Offset" is set to 1 and a term filter is added in the "Query Filter" section to "Set by the current post", so that only connected terms are considered by this view.
The actual code to show the image and the custom term field's URL is added in the loop.
This view can then be nested inside your view that shows "Steps Fasi" posts ( for example "MULTIMEDIA PER FASE" ), in place of those conditional display blocks.
regards,
Waqar