1. Home
  2. ReHub Theme
  3. Advanced tips and customizations
  4. Combine search functions for MDTF and Geo My Wordpres plugins

Combine search functions for MDTF and Geo My Wordpres plugins

MDTF plugin is good plugin for creating search filters on site based on custom meta or taxonomy. Geo My wordpress is one of best Geo and Map search plugins.

Here code which you can combine them. So, when users search on map, then, they can filter results by MDTF plugin and new results will be visible on map

function rh_mdtf_get_post_adress( $get_query ){
  if( $_GET AND isset( $_GET['gmw_address'] ) )
    set_transient( 'mdtf_temp_address', $_GET['gmw_address'][0], 12 * HOUR_IN_SECONDS );
  return $get_query;
}
add_filter( 'gmw_modify_get_args', 'rh_mdtf_get_post_adress' );

function rh_mdtf_set_org_address( $form ){
  $tmp_address = get_transient( 'mdtf_temp_address' );
  if( $tmp_address )
    $form['org_address'] = $tmp_address;
  return $form;
}
add_filter( "gmw_default_form_values", 'rh_mdtf_set_org_address' );

function rh_mdtf_geowp_data( $query_args, $form ) {
  if( class_exists('MetaDataFilter') AND MetaDataFilter::is_page_mdf_data() ) {
    $_REQUEST['mdf_do_not_render_shortcode_tpl'] = true;
    $_REQUEST['mdf_get_query_args_only'] = true;
    do_shortcode('[meta_data_filter_results]');
    $args = $_REQUEST['meta_data_filter_args'];

 		$query_args = array(
      'post_type' => $form['search_form']['post_types'],
      'post_status' => $args['post_status'],
      'tax_query' => $args['tax_query'],
      'posts_per_page' => $form['get_per_page'],
      'paged' => $form['paged'],
      'meta_query' => $args['meta_query'],
      'ignore_sticky_posts' => 1,
      'orderby' => 'distance'
    );
  }
  return $query_args;
}
add_filter( 'gmw_pt_search_query_args', 'rh_mdtf_geowp_data', 10, 2 );

How to customize theme

Was this article helpful to you? Yes No

How can we help?