Skip Navigation

[Resolved] Filter search results by User custom field

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

Problem: I would like to filter the results of a WordPress Archive based on a custom field in the current User's profile.

Use conditional HTML to filter each item in the loop.

[wpv-conditional if="( $(wpcf-my-select) eq 'abc' )"]
  [wpv-post-link] <br />

Relevant Documentation:

This support ticket is created 4 years, 6 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.

This topic contains 2 replies, has 2 voices.

Last updated by samC-4 4 years, 6 months ago.

Assigned support staff: Christian Cox.


I am wanting to display an archive results page of a custom post type that only matches a members predefined fields they filled out on sign up. For example if a user signs up and has filled out the form on their profile that says "3 bedroom house" then I need the archive always match that users saved profile fields. I know I can do this with a custom search view but that is different, I need it to only display based on previously saved profile data.

is that possible? any help would be appreciated.


Hi, one way to do this is to use conditional HTML in the Loop Output editor of your WordPress Archive. For example, this code will hide all posts that do not have the value "abc" saved in the custom field "my-select":

[wpv-conditional if="( $(wpcf-my-select) eq 'abc' )"]
  [wpv-post-link] <br />

This approach can be very effective but has some limitations. When you insert conditional code in an Archive, pagination can be impacted. The hidden posts still count towards the number of posts included on each "page" of results, so you may end up with fewer posts than expected on each page. If pagination is necessary for your archives, you should be aware of the challenges with this approach. We have more information about conditional HTML here:

Another option is to write custom code using the pre_get_posts API offered by WordPress. This API can allow you to apply custom filtering to an archive query using a meta query or tax query, or some other information:

User meta fields are stored in usermeta under a key name in the format "wpcf-" + field slug. So you can access a User field with the slug "birthdate" as "wpcf-birthdate" using the get_user_meta function:


thank you so much 🙂