Skip Navigation

[Resolved] Custom field query filter not working

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

Problem: I have a "select" custom field configured on my posts, and a View of these posts filtered by the custom field. The filter does not seem to be working as expected.

Solution: In general you should compare the custom field content instead of display text in your Query Filter. For example, on the trustees page you should test to see if the value is "1", not "trustees".

Pro tip: use a shortcode attribute to define the value you want to test in your Query Filter. Choose "Board is a string equal to a shortcode attribute 'board'". See the attached screenshot for an example. This way, you can place the same View on each page without needing 3 different Views:

Trustees page: [wpv-view name='your-view-slug' board='1']
Planning page: [wpv-view name='your-view-slug' board='2']
Zoning page: [wpv-view name='your-view-slug' board='3']

This is called passing arguments into Views, and it allows you to create dynamic Views that can be reused in different contexts.

Relevant Documentation:
https://toolset.com/documentation/user-guides/filtering-views-by-custom-fields/
https://toolset.com/documentation/user-guides/passing-arguments-to-views/

This support ticket is created 7 years 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
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 2 replies, has 2 voices.

Last updated by rodF 7 years ago.

Assisted by: Christian Cox.

Author
Posts
#601270
toolset_trouble2.PNG
toolset_trouble1.PNG

I am trying to: Filter a list using Custom Field I created. Field is Board and options are trustees, planning, zoning. I want to only show posts associated with trustees on the trustees page and planning on planning page etc. These are not taxonomies, but rather Post Fields

Link to a page where the issue can be seen:

hidden link

I expected to see:

Just the entrees with "trustees" selected

Instead, I got:

Nothing or all entrees.

#601339
Screen Shot 2017-12-24 at 2.32.05 PM.png

Hi, in general you should compare the custom field content instead of display text in your Query Filter. For example, on the trustees page you should test to see if the value is "1", not "trustees".

Pro tip: use a shortcode attribute to define the value you want to test in your Query Filter. Choose "Board is a string equal to a shortcode attribute 'board'". See the attached screenshot for an example. This way, you can place the same View on each page without needing 3 different Views:

Trustees page: [wpv-view name='your-view-slug' board='1']
Planning page: [wpv-view name='your-view-slug' board='2']
Zoning page: [wpv-view name='your-view-slug' board='3']

This is called passing arguments into Views, and it allows you to create dynamic Views that can be reused in different contexts. More information about that here: https://toolset.com/documentation/user-guides/passing-arguments-to-views/

#601470

Would never have figured that out. Works, thanks.