Reset categories when using the search field

Home Forums Product Support Forums Ajax Search Pro for WordPress Support Reset categories when using the search field

This topic contains 3 replies, has 2 voices, and was last updated by Ernest Marcinko Ernest Marcinko 2 months ago.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #40119
    art2media
    art2media
    Participant

    Hi,

    I have a search set up like in the image attached.
    Now if I deselect most categories and then search for a term that is part of the deselected categories I get no results. Which is to be expected.

    But we need the categories to reset to “all selected” when the user types something in the search field. Is that possible? I guess there is a way using the API. Something like “if search term not empty reset filter”. I didn’t find anything, can you help?

    We use live trigger with Minimal character count 0. Just in case it’s important.

    Thanks!

    Attachments:
    You must be logged in to view attached files.
    #40129
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Hi,

    Well, actually this might be possible via a minor custom code snippet. There is an API function to reset the filters, so ideally I would trigger that when the search input gets focused.

    Try adding this code to the functions.php file in your theme/child theme directory – make sure to have a full server back-up first for safety. For more details you can check the safe coding guidelines.

    add_action('wp_footer', 'asp_footer_custom_script', 999999);
    function asp_footer_custom_script() {
    	?>
    	<script>
    	document.querySelectorAll('input.orig').forEach(function(el){
    		el.addEventListener('focus', function(){
    			ASP.api(el.closest('.asp_m').dataset['id'], 'resetSearchFilters');
    		});
    	});
    	</script>
    	<?php
    }
    Best,
    Ernest Marcinko

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


    #40193
    art2media
    art2media
    Participant

    Hi,

    thank you, that is perfect and works like a charm 🙂

    #40205
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    You are very welcome 🙂

    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 and have not rated already, feel free to leave a rating 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 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.