Support » Plugin: ACF: Better Search » Extending to an ‘exact search’ filter

  • Resolved ALEvancho


    I’m working on getting an extended filter for my search to work with this plugin. The site requires search results that only have exact matches (i.e. if you search 49 you wont get 4900). I have the following code I was able to find that works but does not include ACF data:

    add_filter('posts_search', 'my_search_is_exact', 20, 2);
    function my_search_is_exact($search, $wp_query){
    	global $wpdb;
    		return $search;
    	$q = $wp_query->query_vars;
    	$n = !empty($q['exact']) ? '' : '%';
    	$search = $searchand = '';
    	foreach((array)$q['search_terms'] as $term) :
    		$term = esc_sql(like_escape($term));
    		$search.= "{$searchand}($wpdb->posts.post_title REGEXP '[[:<:]]{$term}[[:>:]]') OR ($wpdb->posts.post_content REGEXP '[[:<:]]{$term}[[:>:]]')";
    		$searchand = ' AND ';
    	if(!empty($search)) :
    		$search = " AND ({$search}) ";
    			$search .= " AND ($wpdb->posts.post_password = '') ";
    	return $search;

    Here I see it is searching $wpdb->posts.post_title and $wpdb->posts.post_content but I also want it to include the ACF data in the post meta. Any ideas on how to achieve this?

    The page I need help with: [log in to see the link]

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Mateusz Gbiorczyk


    Hi @alevancho,

    Thank you for your message.

    Do you need help with this plugin? What you are looking for is this plugin, so you can just install it 🙂

    If you want to achieve an exact search, in the plugin settings, select the option “Search for whole words instead of fragments within longer word”s.

    Please let me know if your problem has been resolved.

    Hey @mateuszgbiorczyk,

    Amazing, I must have missed this setting, that solved my whole issue. Thank you.

    Plugin Author Mateusz Gbiorczyk


    @alevancho, I am glad that we managed to solve your problem. If you are satisfied with using the plugin you can add a review. Thank you very much in advance!

Viewing 3 replies - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.