[Resolved] Conditional output with specific post id and specific post type

Hi, Amit here, I am the Toolset Support Manager, our current ticket queue is calm and I'd like to encourage you to use our new chat support option

In order to try it out please notice that when you open a ticket (while there's availability) you will be able to choose between chat and a normal ticket, both lanes lead to the same supporters and if we decide in chat that the issue needs more time we'll transform it into a normal email ticket for you, so nothing is lost

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.

Tagged: 

This topic contains 14 replies, has 2 voices.

Last updated by Beda 2 months, 3 weeks ago.

Assigned support staff: Beda.

Author
Posts
#1131059

I am trying to:
Display the field by 3 conditions:
1) Specific post id (20)
2) Specific post type ($info)
3) Field not empty
I am using one of posts as preferences of main site page. This post has link, if this link is empty - not show the button.

[wpv-conditional if="( '[types field='single-line' id='15' id='$my_post_type'][/types]' ne '' "]show me[/wpv-conditional]

#1131075

Beda
Supporter

Languages: English (English ) Spanish (EspaƱol ) German (Deutsch )

Timezone: Asia/Bangkok (GMT+07:00)

As I mentioned here https://toolset.com/forums/topic/conditional-display-if-a-custom-field-in-a-specified-post-has-a-certain-value/#post-1131055, Post ID is something absolutely unique in WordPress, it cannot be doubled by Post Types or similar.
If you call a Post ID you already have the most precise, and unique, data that a Post can own.

However, seen from a broader view, in ShortCodes you can add all attributes that are available from the GUI, so if the GUI supports a post type attribute you can add it, if not, then it's not available.

The field can be checked if empty or not with HTML conditions:
https://toolset.com/documentation/user-guides/conditional-html-output-in-views/

#1131077

Thank you for fast reply, Beda. So, construction like this must work:

[wpv-conditional if="( '[types field='single-line' id='15' ][/types]' ne '' "]show me[/wpv-conditional]

But it is not working šŸ™

#1131088

Beda
Supporter

Languages: English (English ) Spanish (EspaƱol ) German (Deutsch )

Timezone: Asia/Bangkok (GMT+07:00)

You need to use the GUI to create conditionals, and it will not result in that shortcode, instead, it will result in:
[wpv-conditional if="( $(wpcf-single-line) ne '' )"]things to show if not empty[/wpv-conditional]

Please use the GUI or our DOC:
https://toolset.com/documentation/user-guides/conditional-html-output-in-views/

#1131089

Beda
Supporter

Languages: English (English ) Spanish (EspaƱol ) German (Deutsch )

Timezone: Asia/Bangkok (GMT+07:00)

Changing the ticket state

#1131091

Okay, i need to display SPECIFIC POST ID on conditional.

[wpv-conditional if="( $(wpcf-internet-shop-link id='20') ne '' )"]test[/wpv-conditional] - not work
[wpv-conditional if="( $(wpcf-internet-shop-link) id='20' ne '' )"]test[/wpv-conditional] - not work
[wpv-conditional if="( '[types field='internet-shop-link' id='20' ][/types]' ne '' "]test[/wpv-conditional] - not work

How to add specific post id, using the GUI?

#1133254

Beda
Supporter

Languages: English (English ) Spanish (EspaƱol ) German (Deutsch )

Timezone: Asia/Bangkok (GMT+07:00)

You could try this:

[wpv-conditional if="( $(wpcf-field).id(15) ne '' )"][types field='field' item='15'][/types][/wpv-conditional]

(change 15, to match the Post ID)

It's actually not in the GUI (only related posts can be added as id) and I reported that to be added.

#1134084

Beda
Supporter

Languages: English (English ) Spanish (EspaƱol ) German (Deutsch )

Timezone: Asia/Bangkok (GMT+07:00)

I apologise, this does not work.
I am not sure why it should, it did yesterday, however, I might have fooled myself here with a logic mistake, today i tried this again and I cannot check if a field of a specific post is empty.

I however then made it work like this:

[wpv-conditional if="( '[types field='toolset-single-line' item='21'][/types]' ne '' )"]
[types field='toolset-single-line' item='21'][/types]
[/wpv-conditional]

I reported this issues.

#1134100

Hello, Beda. Thank you for reply. I did try this code too, but it's not work šŸ™

[wpv-conditional if="( '[types field='internet-shop-link' item='20'][/types]' ne '' )"]
[types field='internet-shop-link' item='20'][/types]
[/wpv-conditional]

It is not good solution, but i solved my promblem - i added new field - checkbox and did new conditional code:

                [types field='check-not-show-link' item='20' state="checked"]
                   <!-- Show nothing -->
                [/types]
                [types field='check-not-show-link' item='20' state="unchecked"]
                   [types field='internet-shop-link' item='20'][/types]
                [/types]

If the new checkbox is checked - the the field is not showing, if checkbox is not checked - the field is showing

#1134105

Beda
Supporter

Languages: English (English ) Spanish (EspaƱol ) German (Deutsch )

Timezone: Asia/Bangkok (GMT+07:00)

Can you grant me access to the site, share the link with the post where the field is stored, and where you check up on the field?
I can then have a look and edit it there if you agree.

#1134134

Beda
Supporter

Languages: English (English ) Spanish (EspaƱol ) German (Deutsch )

Timezone: Asia/Bangkok (GMT+07:00)

Please share the login url, since you modified the native WordPress login-paths. I end up in 404's everywhere.

#1134135

I'm sorry, updated the private message

#1134144

Beda
Supporter

Languages: English (English ) Spanish (EspaƱol ) German (Deutsch )

Timezone: Asia/Bangkok (GMT+07:00)

That's not a single line but a URL field?
Try to compare against raw values, in those cases.

[wpv-conditional if="( '[types field='internet-shop-link' item='20' raw='true'][/types]' ne '' )"]
[types field='internet-shop-link' item='20'][/types]
[/wpv-conditional]
#1134145

Thank you, Beda! You are awesome! It works, and now i know: to compare fields - they must be raw. Thank you and have a good day! Best support team ever!

#1134169

Beda
Supporter

Languages: English (English ) Spanish (EspaƱol ) German (Deutsch )

Timezone: Asia/Bangkok (GMT+07:00)

Great, then we can close here.