Skip Navigation

[Resolved] wpv-conditional returns different results in two nearly identical views

This thread is resolved. Here is a description of the problem and solution.

Problem:

Check current page information in wpv-conditional shortcode.

Solution:

You can get the subtitle field value of current page with shortcode:
[types field='subtitle' item="$current_page"][/types]

Then you can use it in the wpv-conditional shortcode directly, for example:

https://toolset.com/forums/topic/wpv-conditional-returns-different-results-in-two-nearly-identical-views/#post-950022

Relevant Documentation:

https://toolset.com/documentation/user-guides/conditional-html-output-in-views/using-shortcodes-in-conditions/

This support ticket is created 6 years, 5 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 – 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/Hong_Kong (GMT+08:00)

This topic contains 8 replies, has 2 voices.

Last updated by Luo Yang 6 years, 5 months ago.

Assisted by: Luo Yang.

Author
Posts
#948760
Screen Shot 2018-07-16 at 7.16.22 PM.png
Screen Shot 2018-07-16 at 6.36.28 PM.png
Screen Shot 2018-07-16 at 6.37.59 PM.png

I am trying to:

I’m trying to display a line of html conditionally in the same way in two custom post types, using Views. The same Types custom field is being used in both content templates. The views are nearly identical. The specific lines of html and the wpv-conditional shortcode in question in the two content templates are identical.

Attached screenshots show the content templates with html for the respective pages. The conditionally displayed H2 line is at bottom in each. The view named “inside page header - podcast post” gives the expected result, while the view named “inside page header - writing post” does not.

Link to a page where the issue can be seen:

On this page, it’s working. The H2 subtitle (“Elias and Pete discuss law and insurgent cities”) is conditionally displayed.
hidden link

On this page, it’s not working. There should be an equivalent H2 subtitle showing under the H1 title (“What I Saw at the Socialism Conference”).
hidden link

#948943

Hello,

The credentials you provided above is not valid, I get this error:
ERROR: The password you entered for the username toolset support is incorrect

Please check it, make sure it is valid password

#949064

My apologies. I’ve generated a new password now, and checked that it works. How should I send it to you?

#949070

I have enabled the private message box again, please fill it with the new credentials. thanks

#949078
#950004

I have checked it in your website, in the problem URL you mentioned above:
hidden link

I can see the subtitle text "What I Saw at the Socialism Conference" correctly, can you confirm it, it might be a cache problem.
If you are using Views shortcode [wpv-view ...], you can disable cache of Views by adding attribute cached="false", for example:
[wpv-view cached="false"...]

More help:
https://toolset.com/documentation/user-guides/views-shortcodes/#wpv-view

#950011
Screen Shot 2018-07-17 at 11.11.00 PM.png
Screen Shot 2018-07-17 at 11.33.33 PM.png

Luo Yang, thank you for getting into this with me.

The field whose value ("What I Saw at the Socialism Conference") is showing on that page isn’t the subtitle, actually, but the main title, which is taken from a Types field I’ve added called "display title." The field for the subtitle is just called "subtitle." Here are the relevant lines from the content template "Loop item in inside page header — writing post":

<h1>[types field='display-title' item='$current_page'][/types]</h1>
[wpv-conditional if="( $(wpcf-subtitle) ne '' )"]<h2 style="border: none;">[types field='subtitle' item='$current_page'][/types]</h2>[/wpv-conditional]

I’ve added a screenshot showing the fields in the post itself.

I didn’t know about the cache disabling attribute. I’ve added it to the wpv-view shortcode as you suggest.

It may be useful to note that on both custom post types — the post type with the view working correctly as well as this one, where it isn’t working — the wpv-view shortcodes for displaying the respective, nearly identical content templates are placed in GeneratePress "Page Header" posts. (Added a screenshot showing this as well.) It seems like this complicates the query, since there is more than one hierarchical relationship involved. But I am still only beginning to understand how these things function.

#950022

You can get the subtitle field value of current page with shortcode:
[types field='subtitle' item="$current_page"][/types]

Then you can use it in the wpv-conditional shortcode directly, for example:

[wpv-conditional if="( '[types field='subtitle' item="$current_page"][/types]' ne '' )"]<h2 style="border: none;">[types field='subtitle' item='$current_page'][/types]</h2>[/wpv-conditional]

Please test it again, check if it is fixed or not

More help:
https://toolset.com/documentation/user-guides/conditional-html-output-in-views/using-shortcodes-in-conditions/

#950261

Ah, that’s the answer. Thank you!

I knew there must be some way to add a relationship attribute to $(wpcf-subtitle) inside the conditional. It didn’t occur to me that I could just replace $(wpcf-subtitle) with its corresponding Types shortcode and specify the relationship that way.

Do you have any thoughts about why specifying the $current_page relationship is necessary to get the field to display in the view for this post type ("Writing Posts") but not in the view for the other ("Projects")?

#951042

Yes, the $current_page relationship is necessary, it will be able to get information of current page.