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?
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.
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.