Skip Navigation

[Resolved] Adding a Query Filters to a View based on a User Field

This support ticket is created 4 years, 2 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 1 reply, has 2 voices.

Last updated by Luo Yang 4 years, 2 months ago.

Assisted by: Luo Yang.

Author
Posts
#1858131

Hi,

I have a custom post type name "Lead". When the "Lead" are created, they are assigned a Tag Taxonomy named "Attribution". I also have a User Field name "User Attribution"

The "Lead" posts are display inside a view. I want to filter the view to only show the "Lead" that has an "Attribution" tag that is equal to the loged in User's "User Attribution".

In short, I want to filter my view querry based on the logged in user's custom user field.

Is it possible?

#1858279

Hello,

In your case, I suggest you try with Views filter hook wpv_filter_query, for example:
1) Use filter hook wpv_filter_query to trigger a PHP function
https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query
2) In this PHP function, do these:
- Get current logged-in user ID:
https://developer.wordpress.org/reference/functions/get_current_user_id/
- Get "User Attribution" field value:
https://developer.wordpress.org/reference/functions/get_user_meta/
- Then pass the field value into view's query