We're trying to use conditional code to make certain HTML execute only when a custom radio button field has one specific value. Here is the code I'm using:
[wpv-conditional if="( $(wpcf-freelancer-board-member) ne 'no')"]
<div class="tb-field freelancer-board-member" data-toolset-blocks-field="1" data-last-update="1.4">[types field='board-member' output='normal' ][/types]</div>
[/wpv-conditional]
The intent of this code is to add a Board Member designation to a display when the person is a Board Member. You can see an example of this here:
hidden link
But then on people that are not Board Members, we do not want this to display. But no matter what I do with the conditional code, this bit of HTML is still executing and including the word "no" as the value of the field. An example can be seen here:
hidden link
Can you provide the correct syntax for what we're trying to do here? I've tried
[wpv-conditional if="( $(wpcf-freelancer-board-member) eq 'Board Member')"]
[wpv-conditional if="( $(wpcf-freelancer-board-member) eq 'yes')"]
[wpv-conditional if="( $(wpcf-freelancer-board-member) eq 'Yes')"]
But nothing seems to work to get this to not display when the radio button field is set to the No option. Thanks for any assistance you can provide.
Hi,
Thank you for contacting us and I'd be happy to assist.
Assuming that you've set the radio type custom field, to store the raw value 'yes', when checked, this conditional statement should work just fine:
( example screenshot for the setting attached )
[wpv-conditional if="( $(wpcf-freelancer-board-member) eq 'yes')"]
<div class="tb-field freelancer-board-member" data-toolset-blocks-field="1" data-last-update="1.4">
[types field='freelancer-board-member' output='normal' ][/types]
</div>
[/wpv-conditional]
If for some reason, it doesn't work correctly for any particular post, you can check what is stored as the raw value in that custom field by temporarily using this shortcode:
[types field='freelancer-board-member' output='raw'][/types]
I hope this helps and please let me know if you need any further assistance around this.
regards,
Waqar
It didn't work as hoped. It did eliminate the display of "no" on the non board member person, but it also eliminated the display of "Board Member" on the board member person. I tried the output="raw" code and it didn't display anything here.
This is how the field is defined:
Field name Board Member
Field slug board-member
Field type
Description
Options
Display text Custom field content Default
Yes yes
No no
No Default
Add option
Value to show Display the value of this field from the database
Show one of these values:
Yes - Board Member
No
--------------------------------------------------------------------
I tried:
[wpv-conditional if="( $(wpcf-freelancer-board-member) eq 'Yes')"]
<div class="tb-field freelancer-board-member" data-toolset-blocks-field="1" data-last-update="1.4">
[types field='freelancer-board-member' output='normal' ][/types]
</div>
[/wpv-conditional]
[wpv-conditional if="( $(wpcf-freelancer-board-member) eq 'yes')"]
<div class="tb-field freelancer-board-member" data-toolset-blocks-field="1" data-last-update="1.4">
[types field='freelancer-board-member' output='normal' ][/types]
</div>
[/wpv-conditional]
[wpv-conditional if="( $(wpcf-freelancer-board-member) eq 'Board Member')"]
<div class="tb-field freelancer-board-member" data-toolset-blocks-field="1" data-last-update="1.4">
[types field='freelancer-board-member' output='normal' ][/types]
</div>
[/wpv-conditional]
None of those worked. I'm baffled.
Now I'm seeing that the slug is actually just board-member, not freelancer-board-member. So I tried
[wpv-conditional if="( $(wpcf-board-member) eq 'yes')"]
<div class="tb-field freelancer-board-member" data-toolset-blocks-field="1" data-last-update="1.4">
[types field='freelancer-board-member' output='normal' ][/types]
</div>
[/wpv-conditional]
And that didn't work either. That displayed the green background that should be present, but the words "Board Member" did not appear.
Then I tried
[wpv-conditional if="( $(wpcf-board-member) eq 'yes')"]
<div class="tb-fieldboard-member" data-toolset-blocks-field="1" data-last-update="1.4">
[types field='board-member' output='normal' ][/types]
</div>
[/wpv-conditional]
And that didn't display anything. I'm completely baffled by my inability to get this to work. I know the fault is with me in some way, but I can't figure it out. Thanks if you can figure out what I'm doing wrong here.
Thank you for sharing this update.
Most likely, the reason can be that there is some inconsistency between custom field slugs and/or values used for the existing freelancer posts.
Can you please share temporary admin login details, so that I can see how these elements are set up in the admin area?
I'll be in a better position to suggest the next steps, accordingly.
Note: Your next reply will be private and making a complete backup copy is recommended before sharing the access details.
It looks like it is working now. I'm not sure if you did anything, but I saw "Board Member" was displaying above the content. I had to fix the CSS class of the field and it's now displaying properly. I still have an issue to solve with the placement of each of these bits, but that's a CSS issue outside of Toolset's functionality, so I'm not asking for any assistance there. I think we're good on this now.
Thanks for the update and glad that it is working now.
You're welcome to mark this ticket as resolved and start a new one for each new question or concern.
My issue is resolved now. Thank you!