This website uses cookies to personalize your experience. By using this website you agree to our cookie policy.

Reply To: Without UI settings, filter search results by custom fields

Home Forums Product Support Forums Ajax Search Pro for WordPress Support Without UI settings, filter search results by custom fields Reply To: Without UI settings, filter search results by custom fields

#46180
jlajla
Participant

Please disregard!

I found the answer in the documentation itself, apologies.

The solution was to write a plugin, as below, corresponding to my above use case:

`
add_filter(“asp_query_args”, “filter_search_by_user_uuid”, 10, 2);

function filter_search_by_user_uuid($args, $search_id) {
// Replace ‘2’ with the ID of your specific search bar
$target_search_id = 2;

if ($search_id != $target_search_id) {
// If this isn’t the target search bar, don’t modify the query
return $args;
}

// Get the current user ID and retrieve their UUID
$current_user_id = get_current_user_id();
$user_uuid = get_user_meta($current_user_id, ‘user-uuid’, true);

// Check if user UUID is available
if ($user_uuid) {
// Add a post meta filter to the query arguments
$args[‘post_meta_filter’] = array(
array(
‘key’ => ‘user-uuid’,
‘value’ => $user_uuid,
‘operator’ => ‘=’,
‘allow_missing’ => false
)
);
}

return $args;
}

`