• Resolved Tarjanyela

    (@tarjanyela)


    Dear Support-Team

    We’ve got a customer who uses the Ajax Search Lite Plugin combined with the Search Exclude Plugin to exclude certain posts from the search results. While the exclude works on the built-in wordpress search, the Ajax Search Lite search results display all posts.

    Is there a possibility to exclude the posts set by the “Search Exclude” Plugin none the less? I know that you can enter the IDs in the Ajax Load More settings, but that’s not the way to go for my customer.

    Or could you give me a hint where to best modify the plugin code? ??

    Thanks a lot for your help!
    Yvonne

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author wpdreams

    (@wpdreams)

    Hi Yvonne,

    I am not sure if we can integrate to be honest. I am already struggling to keep up with the integration of other plugins, it requires a lot of maintenance.

    Instead of a direct modification to the plugin code, I suggest a custom filter code, to integrate the two plugins.

    The asl_query_add_args filter hook is a good starting point, it lets you add extra query parts to the code. So, if you can get the excluded post IDs via the other plugin API, then using a custom code based on that would do the trick. Something like:

    add_filter('asl_query_add_args', 'my_asl_query_add_args', 10, 3);
    function my_asl_query_add_args($query, $data, $options) {
        // --> Get the array of post IDs via a function
        // $ids = get_excluded_post_ids();
        // $ids = !empty($ids) ? implode(',', $ids) : $ids;
        
        // if ( !empty($ids) ) {
        $query = array(
    	'fields' => '',
    	'join' => '',
    	'where' => "AND $wpdb->posts.ID NOT IN($ids)",
    	'orderby' => '',
    	'groupby' => ''
        ); 
        // }
        return $query;
    }

    This is not a working code, just a sample! Edit it according to the other plugin API.

    Best,
    Ernest M.

    Thread Starter Tarjanyela

    (@tarjanyela)

    Hi Ernest

    thanks a lot for your reply and the suggestion for the filter. I haven’t had a chance to try your suggestion yet, but I will give it a go as soon as I get the chance to. I’ll post the final code as soon as it works ??

    Cheers
    Yvonne

    Thread Starter Tarjanyela

    (@tarjanyela)

    Hi Ernest

    thanks again for your reply, it worked like a charm.

    For the “Search Exclude” Plugin, it stores all IDs as an option, so my final code looks like this – maybe it helps anyone else out there:

    add_filter('asl_query_add_args', 'my_asl_query_add_args', 10, 3);
    function my_asl_query_add_args($query, $data, $options) {
    
    	global $wpdb;
    
    	$ids = get_option('sep_exclude');
    	$ids = !empty($ids) ? implode(',', $ids) : $ids;
    
    	if ( !empty($ids) ) {
    		$query = array(
    			'fields' => '',
    			'join' => '',
    			'where' => "AND $wpdb->posts.ID NOT IN($ids)"
    		);
    	}
    	return $query;
    }

    Thanks for your help.

    Cheers,
    Yvonne

    • This reply was modified 5 years, 4 months ago by Tarjanyela.
    • This reply was modified 5 years, 4 months ago by Tarjanyela.
    • This reply was modified 5 years, 4 months ago by Tarjanyela.
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Search results display Posts excluded by “Search Exclude” Plugin’ is closed to new replies.