HI Ashish,
Sorry for missing out your reply.
Following the steps below you should be able to achieve what you described above:
1) Create a page that will hold the GEO my WP search results. For example we’ll call it “Results”.
2) You need to create the category links of the home page in a way that they will all link to this “Results” with the category slug pass via URL. So for example the link for “Hotel” category will look like https://www.businesslocator.com/results/?category=hotels
3)
- Create new ( or edit existing ) GEO my WP’s Posts Locator form.
- Click on the “Search Form” tab and set the “Search form template” dropdown to “Disable search form”.
- Click on “Page load results” tab, check the “Enable Page Load features” checkbox, choose the post type, check the “Display list of results” checkbox and set the rest of the filters as you wish.
- click on the “Search Results” tab and set the search results as you wish.
4) Edit the “Results” page you create above and add the shortcode of the form you just created ( [gmw form=”ID”] ) to the content of the page.
5) Open the functions.php file of your theme/child theme and place there the script below:
function gmw_filter_form_by_taxonomy_term( $args, $gmw ) {
// make sure we filter the correct form and that the category is in URL
// chnage the value 5 to the form ID of the form you created
if ( $gmw['ID'] != 5 || empty( $_GET['category'] ) )
return $args;
// get the taxonomy term from URL
$term = $_GET['category'];
// pass the taxonomy term that we want to filter
//Change "category" to the taxonomy you need to filter
$args = array(
array(
'taxonomy' => 'category',
'field' => 'slug',
'terms' => $term,
),
);
return $args;
}
add_filter( 'gmw_pt_tax_query', 'gmw_filter_form_by_taxonomy_term', 10, 2 );
Follow the notes in the script to modify it based on your needs.
That’s it. That I believe should work.
Note that creating a “Results” page and linking all the categories to it is just one way. You can probably link the categories to the category archive page and make it work as well. You will need to place the form shortcode in the archive tempalte page and make it work by passing the category to the filter.
Let me know if that helps.