Forums › Forums › Search & Filter Pro › Filter by city and results order
- This topic has 4 replies, 2 voices, and was last updated 7 years ago by Trevor.
-
Anonymous(Private) November 9, 2017 at 3:41 pm #140957
Hi Tevor, great plugin! Congrats!
I configured it in this website: https://www.reumatologia.org.br/associado
Now, I have two questions that I didn’t find in the foruns or in the documentation:1) What the best approach to filter those results by city? I created a custom post type (called “associado“) and added some custom fields through ACF Pro – one of them is a Google Map. I tried add a Post Meta filter with that field, but ACF sends different address formats (sometimes geolocation, sometimes full address). I can’t extract only the city to put in a checkbox.
In your experience, is best to add a new field with ALL cities and filter by this new field? Or add a custom taxonomy?2) I set to display the results in Post Type Archives page, loading results using Ajax. Everything is working fine, but the default order is by post date, and I want to set alphabetical order by default. I tried to set the default order in functions.php file, adding this code:
add_action( 'pre_get_posts', 'my_change_sort_order'); function my_change_sort_order($query){ if( is_post_type_archive( 'associado' ) ): is_post_type_archive( $post_type ) $query->set( 'order', 'ASC' ); $query->set( 'orderby', 'title' ); endif;
It worked, but it blocked the Sort Order function that I have in your plugin. I tried to set a custom querry on archive page too, but it didn’t work. Any help?
Trevor(Private) November 9, 2017 at 4:09 pm #140973So, at this time our plugin cannot filter by Geo Data (e.g. distance from point xxxx, yyyy). You would have to have a field just for City and filter that way.
To use our plugin with maps right now, what I do is use the WP Google Maps plugin (Pro version).
That plugin allows you to create a precise location map for a post, along with a nice info panel, into which you can enter the URL for the post.
In the post, I create a filterable location field (e.g. city), and another field for the ID of the map.
On the single post page you can use PHP to fetch the Map ID from that field and make the shortcode to display the map, and then use the PHP do_shortcode function to display the map where you want it on that single post page.
For an archive page, you might want a map with all the post results pins on. The WP Google Maps Pro plugin allows you to create a mashup shortcode map. Again you use PHP to build the shortcode and again display it using do_shortcode, as shown in this post:
https://support.searchandfilter.com/forums/topic/google-map-api-integration/#post-139818
Anonymous(Private) November 11, 2017 at 10:43 pm #141442Thanks, Trevor!
Let me ask one more thing? How can I show a results count in archive page?
I tried this code:$args = array( 'post_type' => 'my-post-type' ); $the_query = new WP_Query( $args ); echo 'You found '. $the_query->found_posts . ' posts';
But it shows ALL posts in that post type, not only the results.
Any help?
Trevor(Private) November 13, 2017 at 4:30 am #141549Is that code inside the loop, or the Ajax Container? It may need to be. But I do not think you should be creating a new query. All you should need to do is use the current query (whatever variable name it has) in the lat line, replacing $the_query with whatever your is.
-
AuthorPosts