Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Contributor pronskiy

    (@pronskiy)

    Hello Yves,

    Thanks for reporting the problem. I will do some investigation and get back to you soon.

    Best regards,
    Roman

    Plugin Contributor pronskiy

    (@pronskiy)

    Hello Yves,

    Better Search does not respect the WordPress’ mechanism of building query and replaces where clause with its own. However, you can still accomplish your task.

    Add following to your theme’s functions.php file:

    add_filter( 'bsearch_clause_prepare', 'search_exclude_bsearch_clause_prepare');
    function search_exclude_bsearch_clause_prepare($search_ids)
    {
    	global $wp_query;
    	$excluded = $wp_query->query_vars['post__not_in'];
    	$ids = explode(',', $search_ids);
    	$ids = array_diff($ids, $excluded);
    	$search_ids = implode(',', $ids);
    
    	return $search_ids;
    }

    Let me know if this helped you.

    Cheers!
    Roman

    Thread Starter Anticosti

    (@anticosti)

    Hi Roman ??

    Yes Sir!!!
    With the above (copied/pasted) it works perfect!!!
    Good Job Roman ?? ??

    Thanks a bunch ??

    Sincerly,

    Yves

    Thread Starter Anticosti

    (@anticosti)

    Oh ?? Sorry about that Roman ??
    I guess I was a little too excited ??
    Went through deep testing and… It is not working for me…

    Cheers,

    Yves

    Plugin Contributor pronskiy

    (@pronskiy)

    Hi Yves,

    Could you please give a little more of a description of what is working with the code above and what us not? Or maybe you have sort of staging server where I could have a look?
    Also you can message me in skype (romanpronskiy) or email ([email protected]).

    Thread Starter Anticosti

    (@anticosti)

    I now have you in my Skype contacts ??
    but we are not in the same time zone ??

    Thread Starter Anticosti

    (@anticosti)

    A great thank you to Roman who kindly helped me solved this issue for me with this great piece of Art by coding:

    add_filter('get_bsearch_matches', 'search_exclude_get_bsearch_matches');
    function search_exclude_get_bsearch_matches($matches)
    {
    	global $pluginSearchExclude;
    	$method = new ReflectionMethod('SearchExclude', 'getExcluded');
    	$method->setAccessible(true);
    	$excluded = $method->invoke($pluginSearchExclude);
    
    	$matches[0] = array_filter($matches[0], function($item) use ($excluded) {
    		return !in_array($item->ID, $excluded);
    	});
    
    	return $matches;
    }

    Thanks again Roman ! ??
    You Rock!

    Sincerly,

    Yves

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Not working with Better Search (plugin)’ is closed to new replies.