Searching pages by custom fields

Home Forums Product Support Forums Ajax Search Pro for WordPress Support Searching pages by custom fields

This topic contains 15 replies, has 2 voices, and was last updated by Ernest Marcinko Ernest Marcinko 3 years, 10 months ago.

Viewing 16 post (of 16 total)
  • Author
    Posts
  • #27780
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Hi Kev,

    The issue is, that “Asia” also matches “Australasia“. So the filter also shows items matching items from that value as well. Unfortunately using an “EXACTLY LIKE” operator is not possible in this case, as multiple values might be present in the filter, because of using ACF.

    I think the easiest possible solution is to use a custom code, that appedns additional characters to the location filter values. It would be very hard to explain why, it is related to the data storage method and how the database query sees that.

    Try adding this custom code to the functions.php in your theme/child theme directory. Before editing, please make sure to have a full site back-up just in case!

    add_filter('asp_pre_get_front_filters', 'asp_change_a_filter', 10, 2);
    function asp_change_a_filter($filters, $type) {
      foreach ($filters as $k => &$filter) {
    	  if ( $filter->type() == 'custom_field' && $filter->data['field'] == 'location' ) {
    		 foreach ( $filter->get() as $fk=>$fv ) {
    			 if ( $fv->value != '' )
    				$filter->attr($fv->value, 'value', '"'.$fv->value . '";');
    		 }
    	  } 
      } 
      return $filters;
    }

    This will resolve the issue.

    Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


Viewing 16 post (of 16 total)

You must be logged in to reply to this topic.