Skip Navigation

[Resolved] What is the correct syntax to conditionally display based on wpv-post-type?

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

Problem:

Use shortcode [wpv-post-type] in [wpv-conditional].

Solution:

You can use shortcode [wpv-post-type] directly, for example:

https://toolset.com/forums/topic/what-is-the-correct-syntax-to-conditionally-display-based-on-wpv-post-type/#post-915572

Relevant Documentation:

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 – 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 3 replies, has 2 voices.

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

Assisted by: Luo Yang.

Author
Posts
#915412

I have search results that return two different post types.

I can print the post type using [wpv-post-type] and view it OK

However when I tried to conditionally show segments based on post type it does not work.

I'm assuming it should be something like:

[wpv-conditional if="( $(wpv-post-type) eq 'org' )" debug="true"] 
<div>
  OUTPUT
</div>
[/wpv-conditional]

But this does not work.

The debug output is:

####################
wpv-conditional attributes
####################
Array
(
    [if] => ( $(wpv-post-type) = 'org' )
    [debug] => true
)

####################
Debug information
####################
--------------------
Original expression: ( $(wpv-post-type) = 'org' )
--------------------
--------------------
Converted expression: ( '' = 'org' )
--------------------
#915572

Hello,

The variable "$" in wpv-conditional shortcode works only for the custom post field, in your case, you can use shortcode [wpv-post-type] directly, for example:

[wpv-conditional if="( '[wpv-post-type]' eq 'org' )" debug="true"] 
<div>
  OUTPUT
</div>
[/wpv-conditional]
#915639

Perfect! Thank you 🙂

#916075

You are welcome