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]
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/
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 🙁
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/
Changing the ticket state
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?
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.
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.
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
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.
Please share the login url, since you modified the native WordPress login-paths. I end up in 404's everywhere.
I'm sorry, updated the private message
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]
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!
Great, then we can close here.