Skip Navigation

[Résolu] How to display the option chosen in Checkboxes?

This support ticket is created Il y a 4 années et 10 mois. 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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+01:00)

Marqué : 

This topic contains 5 réponses, has 2 voix.

Last updated by Nigel Il y a 4 années et 10 mois.

Assisted by: Nigel.

Auteur
Publications
#1268997

I have a field group forex-broker.

In that field group, i have a field: country-of-origin

And I added about 200 options to it. Every option has its own unique value to be stored to the database. 1 to 200.

I am working on the content template. And I want to do a conditional output where if the option number is chosen, it will be displayed on the front end.

So, I tried this: I have ticked option 1, 29, 30.

And I have following code for the content template:

<!-- Testing if option 1 is selected, whether it will show it or not-->
[wpv-conditional if="( $(country-of-origin) eq '1' )"]
<p>[types field='country-of-origin' separator=', '][/types]</p>
[/wpv-conditional]

Output as I expected: 1, 29, 30

But when I put option 29 in the code:

<!-- Testing if option 29 is selected, whether it will show it or not-->
[wpv-conditional if="( $(country-of-origin) eq '29' )"]
<p>[types field='country-of-origin' separator=', '][/types]</p>
[/wpv-conditional]

No output at all.

So I suspect my way of doing the thing is wrong.

My question is that: How do i show specifically only 1 item from the checkboxes eventhough multiple options are chosen?

#1269137

Nigel
Supporter

Languages: Anglais (English ) Espagnol (Español )

Timezone: Europe/London (GMT+01:00)

I think what you are trying to do is covered here: https://toolset.com/documentation/user-guides/conditional-html-output-in-views/displaying-taxonomies-conditionally/#specific

If you try that and have problems, let me know.

#1269709

Hi, I can't resolve the problem with your example. Your example is for the taxonomy. My problem is with the checkboxes. The problem is that checkboxes save the values as an array in the database.

I have 200 options for the checkboxes. If several options are chosen by the users. And I want to specifically check whether one of the options is checked. And then output that one option, not all other checked option.

Can you please give me the exact code? The above situation is the real case situation on my current project.

#1270323

Nigel
Supporter

Languages: Anglais (English ) Espagnol (Español )

Timezone: Europe/London (GMT+01:00)

Sorry, if it's a checkboxes field rather than a taxonomy then you need to specify the option number, which is described here: https://toolset.com/documentation/user-guides/conditional-html-output-in-views/checking-fields-and-other-elements-for-emptynon-empty-values/#checking-types-checkboxes-field-for-non-empty-value

Let me know if that works in your scenario.

#1274227

Maybe I explain the situation again.

I have added about 200 countries to my checkboxes.
I would love to display in the view all the brokers with let say "Australia" is checked.

How do I do it precisely?

#1274317

Nigel
Supporter

Languages: Anglais (English ) Espagnol (Español )

Timezone: Europe/London (GMT+01:00)

Screenshot 2019-06-21 at 09.13.10.png

In that case you would edit the View and insert a Query Filter for this checkboxes custom field and specify "Australia" as the value to filter by, although it sounds like the saved values from your field are numbers, so you would be testing the number that corresponds to Australia.

If you cannot see the Query Filter section in your View, go to the screen options tab at the top of the page and make sure Query Filter is checked.

You could specify one value, using equals. But you may find it useful to specify several values, which you can do with the IN comparison, as shown in my screenshot.

Also note that you can re-use the same View and pass the value to be used in the filter to the View, rather than creating lots of Views with hard-coded values.

In that case you would choose "Shortcode attribute" as the source of the value. Choose a name for the attribute (e.g. "filter"), and then wherever you insert the View you can pass the value via that attribute, e.g.

[wpv-view name="my-view" filter="23"]

And you could even use other shortcodes to pass the filter value dynamically, depending on what you are aiming to do.

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