Home › Forums › Product Support Forums › Ajax Search Pro for WordPress Support › Help with showing correct posts on load
- This topic has 9 replies, 2 voices, and was last updated 5 years, 11 months ago by
Ernest Marcinko.
-
AuthorPosts
-
June 14, 2020 at 9:28 am #27848
liammaurer86
ParticipantWhen visiting an archive page on my website, the filter always defaults to the region: “Brisbane” when in this case I want it to show “Gold Coast” (see link). How do I get it to do this when visiting the archive page?
https://mychoiceschools.com.au/queensland/qld-regions/gold-coast/
More details: currently using an Elementor template called “QLD School Archive Page” I have followed the docs on how to set-up correctly and all works well apart from this.
Any help would be appreciated. Thanks.
June 15, 2020 at 9:55 am #27855Ernest Marcinko
KeymasterHi,
Try turning on the auto-populate feature with these settings (empty phrase): https://i.imgur.com/g7Sl4NE.png
That should very likely do the trick, by triggering the search with the selected default options.June 15, 2020 at 10:26 am #27857liammaurer86
ParticipantHi Ernest,
Thanks for your reply. Unfortunately, that didn’t seem to work. Would you be able to take another look at it for me?
Thanks,
LiamJune 15, 2020 at 11:52 am #27859Ernest Marcinko
KeymasterYou cannot access this content.
June 15, 2020 at 11:56 am #27861liammaurer86
ParticipantHi Ernest, sorry I was fiddling with some things. It should be back now.
June 15, 2020 at 12:02 pm #27863Ernest Marcinko
KeymasterThanks! I just tried that page, and it works on my end, the search triggers and enables with the default filters configuration, see video: https://youtu.be/tq619ASHYRY
June 15, 2020 at 12:05 pm #27864liammaurer86
ParticipantBut it should show “Gold Coast”. See image below
June 15, 2020 at 12:33 pm #27870Ernest Marcinko
KeymasterOh, I see what you mean now.
The only way to do that is via custom coding. The filter value needs to be conditionally set via the API.
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_tax_filter', 10, 2); function asp_change_tax_filter($filters, $type) { $taxonomies = 'qld_regions'; // Comma separated list of taxonomies // --- DO NOT CHANGE ANYTHING BELOW --- if ( is_archive() ) { $taxonomies = explode(',', $taxonomies); foreach ( $taxonomies as $taxonomy ) { $taxonomy = trim($taxonomy); foreach ($filters as $k => &$filter) { $term_id = get_queried_object()->term_id; if ($type == 'taxonomy' && $filter->data['taxonomy'] == $taxonomy) { $filter->unselect(); $filter->select($term_id); } } } } return $filters; }Unfortunately I cannot guarantee that this is going to work at all, but it should be a good start.
June 15, 2020 at 12:51 pm #27872liammaurer86
ParticipantThat’s fixed it! A really great plugin by the way, thanks!
June 15, 2020 at 12:53 pm #27873Ernest Marcinko
KeymasterYou are very welcome, and thanks for the kind words 🙂
If you don’t mind, I will close this topic soon and mark it as resolved, feel free to open another one if you have other questions or issues.
If you like the plugin, feel free to rate it on your codecanyon downloads page, it’s greatly appreciated.
-
AuthorPosts
- You must be logged in to reply to this topic.