Skip Navigation

[Resolved] Filters by custom fields

This support ticket is created 3 years, 3 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
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

This topic contains 4 replies, has 2 voices.

Last updated by comercial2 3 years, 3 months ago.

Assisted by: Luo Yang.

Author
Posts
#2205719

Hello, I am doing a view filtering by custom fields (this: https://toolset.com/documentation/legacy-features/views-plugin/passing-arguments-to-views/), and this custom field can have one, two or more values and I pass this information with a shortcode attribute. How can I do this?
Example:
I have elements with a field called "valor" with values: "1", "2" or "3"
In the view shortcode, how can i pass values "1" and "2" ?
These examples don't run:
[wpv-view name="view-test" valuesforfilter="1;2"]
[wpv-view name="view-test" valuesforfilter="1&2"]
[wpv-view name="view-test" valuesforfilter="1,2"]
Only works if i pass only one value:
[wpv-view name="view-test" valuesforfilter="1"]
or
[wpv-view name="view-test" valuesforfilter="2"]

#2205825

Hello,

How do you setup the custom field "valor"? a custom select field? how do you setup the filter in post view? can you take a screenshot for it?
I need to test it in my localhost, thanks

#2206067
screenshot.png

It is a select custom field (screenshot part1), (but it could be a checkbox custom field and could have one or more values selected)
View filter setup is like screenshot part 2, and it works only if value "tarifascontratadasqueaparecen" is one
This works ok

[wpv-view name="view-test" tarifascontratadasqueaparecen="1"]

How can i do that this works correctly?:

[wpv-view name="view-test" tarifascontratadasqueaparecen="1,2"]
#2206631

Thanks for the details, you can use "IN" Comparison function in the filter, for example: edit the post view, setup the filter as below:
my-field is a string in VIEW_PARAM(tarifascontratadasqueaparecen)

Then setup view's shortcode like this:
[wpv-view name="view-test" tarifascontratadasqueaparecen="1,2"]

More help:
https://toolset.com/documentation/user-guides/views/filtering-views-by-custom-fields/
IN: A list of values Checks if the custom field value is within the list of compare values

#2206743

Problem solved. Thank you!!!