AND logic between post tag multiselect

Home Forums Product Support Forums Ajax Search Pro for WordPress Support AND logic between post tag multiselect

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

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #32959
    yair07
    yair07
    Participant

    I am trying to implement a post tag multiselect filter to narrow down the search to only the selected tags. for example when a user selects the tag “Friendly people” and also the tag “Beach” I want the search results to show only destinations which have the tags “Friendly people” AND “Beach”.
    This is a simple AND logic but it seems that it can’t be implemented. I’ve tried every possible combination of the settings “Taxonomy terms checkbox/multiselect connection logic” and “Logic between taxonomy groups” but it still always displays destination that have at least one of the tags (OR).
    Why isn’t this working, an I missing something crucial?

    Thanks.

    #32963
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Hi,

    There is no option for that unfortunately, the logic automatically falls back to “OR” when using the multiselect. There still might be a way to force it programmatically.

    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_filter("asp_query_args", "asp_query_args_change1", 10, 2);
    function asp_query_args_change1($args, $search_id) {
    	foreach ($args['post_tax_filter'] as $k => &$item) {
    		if ( $item['taxonomy'] == 'post_tag' ) {
    			$item['logic'] = 'andex';
    		}
    	}
    	return $args;
    }
    Best,
    Ernest Marcinko

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


    #32969
    yair07
    yair07
    Participant

    That worked beautifully, Thanks!

    I would recommend adding this feature to the plugin since I am sure this is a function many users might need.

    #32976
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    We surely will, the filters section is currently at major rework, it is already in there 🙂 We hope to release it within the next couple of months.

    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.