Skip Navigation

[Closed] Map search with multiple Addresses per post type

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
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10: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/Kolkata (GMT+05:30)

This topic contains 12 replies, has 3 voices.

Last updated by Mateus Getulio 3 weeks, 6 days ago.

Assisted by: Minesh.

Author
Posts
#2774539

Jim

Tell us what you are trying to do?
I have a custom post type that allows 3 separate Addresses. I have a search feature that searches for these post types but I can only figure out how to get it to search on the first address provided. How can I have the search work for multiple Addresses per post type?
Is there any documentation that you are following?
https://toolset.com/documentation/programmer-reference/maps/
Is there a similar example that we can see?
No
What is the link to your site?
hidden link

#2775964

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

Do you mean you have added three different address fields and with the custom search you have, you only want to one address field for search and whatever address string is added to that search box it should be used to search within all those three address custom fields - is that correct?

if so, can you please share problem URL where you added the custom search as well as admin access details.

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I have set the next reply to private which means only you and I have access to it.

#2777376

Mateus Getulio
Supporter

Languages: English (English )

Timezone: America/Sao_Paulo (GMT-03:00)

Hello there,

This is a quick follow up to let you know Minesh is not available today but he'll be back shortly and reply to you as soon as possible.

Thank you for your understanding.
Mateus

#2777950

Jim

Thanks Mateus.

Any idea when Minesh will be back? Or, can you take a look?

#2777992

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Well - I see the following code added to "Custom code" section offered by Toolset with the code snippet "noresults":
=> hidden link

add_filter( 'wpv_filter_query', 'func_display_no_result_by_default_and_more', 10, 3 );
     function func_display_no_result_by_default_and_more( $query_args, $setting,$view_id ) {
    //// 4952 is your view ID, please adjust view ID if required
    if($view_id == 4952) {    
        if(!isset($_GET['wpv_view_count'])) {
            $query_args['post__in'] = array(0);
        }
      	if(array_key_exists('meta_query', $query_args)){
        	foreach($query_args['meta_query'] as $subkey=>$subvalue){
            	error_log(print_r($subkey,true));
              	error_log(print_r($subvalue,true));              
              if (is_array($subvalue)){
              	if (in_array('wpcf-business-1-city',$subvalue)){
               		$orascautat = $query_args['meta_query'][$subkey]['value'];
                	$query_args['meta_query'][$subkey]=array(
                    		'relation' => 'OR',
                            array(
                              'key' => 'wpcf-business-1-city',
                              'value' => $orascautat,
                              'type' => 'CHAR',
                              'compare' => 'LIKE'
                            ),
                            array(
                              'key' => 'wpcf-business-2-city',
                              'value' => $orascautat,
                              'type' => 'CHAR',
                              'compare' => 'LIKE'
                            ),
                            array(
                              'key' => 'wpcf-business-3-city',
                              'value' => $orascautat,
                              'type' => 'CHAR',
                              'compare' => 'LIKE'
                            ),
                            array(
                              'key' => 'wpcf-home-city',
                              'value' => $orascautat,
                              'type' => 'CHAR',
                              'compare' => 'LIKE'
                            )
                    ); 
                }
              }

				error_log('-------------------------------------------------');
                
            }
        }
    }
       error_log(print_r($query_args,true));
    return $query_args;
}

I see you added some meta_query, I would like to know do we need to keep this or as I do not see field "wpcf-business-1-city" added to the page:
- hidden link

#2778069

Jim

Hi Minesh.

Thank you very much for your reply. Are these messages all private now? If they aren't, I would like them to be.

That custom code is related to the 'Search by city name instead of radius' option, which is off by default.

The search part that is in question here is related to the Location search of this form that is seen in this code on the 'Search and Pagination' section for this view:
<div id="distancesearch" class="f-group">[wpv-control-distance distance_unit_url_param="toolset_maps_distance_unit" distance_radius_url_param="toolset_maps_distance_radius" distance_center_url_param="toolset_maps_distance_center" compare_field="address" default_distance="10" default_unit="km" inputs_placeholder="Results within %%DISTANCE%% of: %%CENTER%%"]</div>

The 'address' entered here is only searching in business-1-address but I need it to show results also for business-2-address and business-3-address as well.

#2778149

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Using Distance filter you can combine only one address field.

In order to workaround this, I've created the following views and all the following views is set to return the post IDs and having same Query Filters added as per the original view:
- hidden link

Distance
Show posts within 15km radius of address/coordinates provided using toolset_maps_distance_center URL parameter.

Taxonomy filter
Select posts with taxonomy:
Active Techniques slug in one of those set by the URL parameter wpv-active-technique
eg.
hidden link
AND
Treatments Specialties slug in one of those set by the URL parameter wpv-treatments-specialty
eg. hidden link

Custom field filter
Select items with field:
Gender is a string equal to URL_PARAM(wpv-wpcf-gender)
AND
Business 1 City is a string like URL_PARAM(wpv-wpcf-business-1-city)

Post search filter
Filter post content and title by a text search that will be added manually using the shortcode [wpv-filter-search-box]

For address-1:
- hidden link
For address-2:
- hidden link
For address-3:
- hidden link

Then I've added the "toolset-custom-code" code snippet to "Custom Code" section offered by Toolset:
=> hidden link

function func_update_distance_radius_from_urlparam( $view_settings, $view_id ) {
 
  $allowed_views = array(56427,56423,56425);
 
  if (in_array($view_id,$allowed_views)) {
    
    if(isset($_REQUEST['toolset_maps_distance_radius']) and
       $_REQUEST['toolset_maps_distance_radius']!='') {
       
 		$view_settings['map_distance_filter']['map_distance']= $_REQUEST['toolset_maps_distance_radius'];
    }
     
    
  }
  return $view_settings;
}
add_filter( 'wpv_view_settings', 'func_update_distance_radius_from_urlparam', 5, 2 );

add_filter( 'wpv_filter_query', 'func_text_search_with_distance', 10, 3 );
function func_text_search_with_distance($query_args,$view_settings, $view_id ){
 
if ( $view_id == 4952 ) {
 
                     
                 
                              //// getting distance search results
                              $geo_result = array();
 //$address1_result = do_shortcode('[wpv-view name="therapists-search-map-address1" cached="off"]');
 //$address2_result = do_shortcode('[wpv-view name="therapists-search-map-address2" cached="off"]');
 //$address3_result = do_shortcode('[wpv-view name="therapists-search-map-address3" cached="off"]');
  
   $address1_result = get_view_query_results( 56427 );
   $geo_result =  array_merge($geo_result,$address1_result);
  
   $address2_result = get_view_query_results( 56423 );
   $geo_result =  array_merge($geo_result,$address2_result);
  
   $address3_result = get_view_query_results( 56425 );
   $geo_result =  array_merge($geo_result,$address3_result);
  
   $final_result = array();
   if(!empty($geo_result)){
    
     foreach($geo_result as $k=>$v):
     	$final_result[] = $v->ID;
     endforeach;
   
   }
  
                            
   $query_args['post__in'] = $final_result ;  
  
  }
 return $query_args;
}

Now, when I search for the address "Chelsea, QC, Canada" I can see the "Paul Phillips" is shown with the result.
- hidden link

Can you please confirm it works as expected.

#2778217

Jim

Hi Minesh.

Thank you so much. In my initial testing, it appears to be working as expected.

To get this working on my production site, do I need to add the three views and the custom code snippet?

Is there anything else I need to do?

Also, do you know how I would also get the 'Search by city name instead of radius' option to also search all three addresses?

Thanks again!

#2778266

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Glad to know that the solution I shared help you to resolve your issue.

To get this working on my production site, do I need to add the three views and the custom code snippet?

Is there anything else I need to do?
====>
Yes - you need to add those three newly created views and add the custom code I shared. Make sure to adjust the View IDs as required to code snippet I shared.

As per our support policy, we entertain only one question per ticket. This will help other users searching on the forum as well as help us to write correct problem resolution summery.

May I kindly ask you to open a new ticket with every new question you may have.

#2778833

Jim

Thank you. Please keep this ticket open a bit longer as I try to implement this on production.

#2779175

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Ok fine - Please let me know how it goes.

#2780077

Jim

Please keep this open.

#2780526

Mateus Getulio
Supporter

Languages: English (English )

Timezone: America/Sao_Paulo (GMT-03:00)

Hello there,

We're marking the ticket as pending to give you time to implement it.

Please keep us posted.
Mateus

The topic ‘[Closed] Map search with multiple Addresses per post type’ is closed to new replies.