I have created nested views in which one view displays fields from one post type and then displays fields from another post-type where the value of a field in post type one matches the value of a field in post type two. It works as expected if there is a match. However, if there is not a match, it displays the first view but for the second view it displays "no items found".
My question is How do I accomplish the following: If the view "t_color-view" has no items/is empty don't display the view template "loop item in T_Fruits".
Hi Shane. I'm afraid that is not the solution. I know how to edit that text out. The "no results" shows up in the second view ("color view"), because it's empty:
What I'm asking is how do I not display the results of THIS view ("fruit view") when "color view" is empty.:
[wpv-post-body view_template="Loop item in T_Fruits"]
Here's an example output:
[fruit view item]: Banana
[color view item]:No items found Pear
Light Green
So when color view returns "no items found" I don't want "fruit view item" to display. (I know how to remove the "no items found" from color item; just showing that for clarity.) So, in the above example Banana would not display. Pear and Light Green would.
A link to the view? I'm not quite sure what you need there. You have access to the back end of my site, right? The two views are T_Fruits and T_Color view. T_Fruits is the parent view.
Anxious to hear your thoughts on this, today hopefully...
I tried my methods but it doesn't seem that this is going to work out because there are too many quotation missmatch when using the conditional statements to check the view.
I would suggest keeping the Post in display and just not let anything display if the t_color view doesn't have any results. Thats because the Parent view is built to determine what the child view displays and not the other way around.
This might be achievable with some custom coding but its out of the scope of our support forum.
No knowing what was tried I don't know what didn't work. But is there not a way in which one can use the wpv-attribute short code to write a conditional statement? e.g [wpv-attribute name="code"']
Now we can use a conditional on [wpv-attribute name="code"'] but this is done within the child view to get the value of what is passed into it.
The conditional won't affect the parent view at all. Any conditional that is done will need to be done to the parent view but since we are not able to add an entire view to a conditional statement then we aren't able to not display the parent value.
I'm not sure I agree/understand what you are saying about the way the parent and child are constructed. The two views work this way:
Parent view displays the title and date fields from Fruits. Child View displays all posts from Colors where the title and date fields match the title and date fields of the parent view. Conceptually, I'm not seeing why it wouldn't be possible to state a condition that says the reverse:
If there are no posts in the child view that match the specified values in the parent view, don't display the fields from the parent view. You would apply that condition to the content template in the parent view, and the fields in the parent view wouldn't display if the condition was not met.
The problem is that the Parent View is independent of what the child view displays, however the child view is dependent on the parent.
Now since the parent view has no dependency then we are not able to adjust the output based on the child. The reason for this is because we are not able to use the conditional statement of the child view shortcode. If it was possible to do this then we could check for when the view returns "no results found" and then customize the output based on that.
Since we can't do this then it wouldn't be possible.
My goal is to accomplish not displaying child and parent when there is not a match between the two, however that might be accomplished. I'm a novice but that doesn't feel like that should be so challenging, and if Toolset can't be used to accomplish that in some way it seems like a major limitation of Views.
I feel like there is a solution out there that relies on testing whether the child view has an output and then using that in a conditional statement for the parent view, such as this (but I'm not sure how to adapt it to my situation).