Skip Navigation

[Resolved] Display if a custom field in a specified post has a certain value

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

Problem:
How can I check a specific post field value in a Conditional HTML?

Solution:
You can use the GUI and check against a Views Post Field of your choice.
Then, after inserting the HTML Condition, edit the Views Post Fields Shortcode to address the specific ID of the Post.
Example:
[

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

Relevant Documentation:
https://toolset.com/documentation/user-guides/conditional-html-output-in-views/

This support ticket is created 6 years, 10 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
- - 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00
- - - - - - -

Supporter timezone: Asia/Ho_Chi_Minh (GMT+07:00)

This topic contains 4 replies, has 3 voices.

Last updated by Beda 5 years, 6 months ago.

Assisted by: Beda.

Author
Posts
#532381

I am trying to set conditional output based on the value of a custom field in another post e.g.

I have a post type type called Global with a single post called Global Settings.
The post contains custom fields with values which are used within content templates of another post type. This works fine when simply calling the fields specifying the field id. No problems with that.

I want to be able to use a custom field value in Global Settings to set conditional output e.g.

Custom field : xyz-show-hide
2 options are show and hide
If xyz-show-hide set to hide the conditional output in the content template is hidden.
If xyz-show-hide set to show the conditional output is displayed.

#532405

OK, here we have a serious UX issue, and I would even say, a data structure problem in Views.

With the Conditional GUI it's simply impossible to set an ID to a Types Field in a Conditional and that is exactly what we are encouraged to use, when we want to compare a Types Custom Field.

So to solve it, use a Views ShortCode instead.
You can use the wpv-post-field ShortCode.

There, you can set an ID.

So the HTML Condition would look like this:

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

This checks upon Post ID 15 > Single Line Field.

That is not possible with the Types Custom Field HTML Condtional, but the results are the same.

I will now push for a proper update of the GUI and a rewamp of the workflow.
This is cumbersome as it is right now.

Please let me know if I can assist you elsehow

#532627

I will give that a try. Thank you.

#1131055

It is not work, if you need specific post id and specific post type. PLease, help, i need something like this:
[wpv-conditional if="( '[types field='single-line' id='15' id='$my_post_type'][/types]' ne '' )"]show me[/wpv-conditional]

#1131057

Post ID always is unique, I do not understand why you would need to pass a type as well, which is not supported anyway.
You cannot pass double ID's.

Please open a new ticket in case you still have questions on this.

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.