Help with showing correct posts on load

Home Forums Product Support Forums Ajax Search Pro for WordPress Support Help with showing correct posts on load

This topic contains 9 replies, has 2 voices, and was last updated by Ernest Marcinko Ernest Marcinko 2 years, 1 month ago.

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #27848
    liammaurer86
    liammaurer86
    Participant

    When 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.

    #27855
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Hi,

    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.

    Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


    #27857
    liammaurer86
    liammaurer86
    Participant

    Hi 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,
    Liam

    #27859
    Ernest Marcinko
    Ernest Marcinko
    Keymaster
    You cannot access this content. Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


    #27861
    liammaurer86
    liammaurer86
    Participant

    Hi Ernest, sorry I was fiddling with some things. It should be back now.

    #27863
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Thanks! 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

    Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


    #27864
    liammaurer86
    liammaurer86
    Participant

    But it should show “Gold Coast”. See image below

    View post on imgur.com

    #27870
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Oh, 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.

    Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


    #27872
    liammaurer86
    liammaurer86
    Participant

    That’s fixed it! A really great plugin by the way, thanks!

    #27873
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    You 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.

    Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


Viewing 10 posts - 1 through 10 (of 10 total)

You must be logged in to reply to this topic.