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
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
My apologies. I’ve generated a new password now, and checked that it works. How should I send it to you?
I have enabled the private message box again, please fill it with the new credentials. thanks
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
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.
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/
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")?
Yes, the $current_page relationship is necessary, it will be able to get information of current page.