Skip Navigation

[Resolved] Not Display one View when a different view is empty

This support ticket is created 6 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
- 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

Tagged: 

This topic contains 11 replies, has 2 voices.

Last updated by briana-5 6 years, 5 months ago.

Assisted by: Shane.

Author
Posts
#922813

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

Here's the code

<wpv-loop>
		 [wpv-post-body view_template="Loop item in T_Fruits"]
          [wpv-view name="t_color-view" code="[types field='fruitcode' output='raw'][/types]" wpvdate="[types field='fruit-date' output='raw'][/types]"]
		</wpv-loop>

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

#923087

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Brian,

Essentially you don't want the "No Results Found" to be displayed.

You can do this by removing the text from the View loop output section.

Please let me know if this helps.
Thanks,
Shane

#923109

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:

           [wpv-view name="t_color-view" code="[types field='fruitcode' output='raw'][/types]" wpvdate="[types field='fruit-date' output='raw'][/types]"]

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.

#923635

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Briana,

This might be a little tricky to do.

Would you mind allowing me to have access to the site to see how the views are setup?

Does the fruit view require any information from another view?

Please let me know.
Thanks,
Shane

#924157

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Briana,

Could you send me a link to the parent view ?

I think I have an idea how to get this working.

Thanks,
Shane

#924181

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

#924320

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Briana,

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.

Thanks,
Shane

#924843

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"']

#924891

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Briana,

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.

Thanks,
Shane

#924931

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.

That's not possible?

#948660

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Briana,

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.

Please let me know if this was a bit clearer.

Thanks,
Shane

#952359

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

https://toolset.com/forums/topic/shotcode-to-check-if-a-view-has-output/

Or changing the way in which the two views are related to one another to resolve the limitation you describe above.

Oh well. Moving on.