• Resolved Underscorefunk

    (@underscorefunk)


    I’m trying to exclude a set of page IDs from search results via pre_get_posts and setting post__not_in with an array of the IDs. This works perfectly fine with the plugin disabled and the $query->results looks as it should. When the plugin is enabled, all of the pre-filtering is overwritten. I gave the action higher priority and it still doesn’t change things.

    Any ideas? I couldn’t find anything about this on the forums or support sites 🙁

    http://wordpress.org/extend/plugins/relevanssi/

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter Underscorefunk

    (@underscorefunk)

    Looks like the solution is to use some of relevanssi’s filters instead. Here’s the solution. Hope this helps some folk out there. In this situation I wanted to selectively exclude an ’employees’ page and all child pages if the current user isn’t allowed to see ’employee content’

    I’ll probably write a sql query that is more efficient to only grab IDs instead of get_pages. But this is proof of concept.

    Also, the ID of 7324 for the employee page will be replaced with something more flexible and/or a theme option. 🙂

    function uf_search_filter( $query_restrictions ) {
    
    	if ( current_user_can( 'read_employee_only_content' ) ) {
    		return $query_restrictions;
    	}
    
    	$pages = get_pages( 'child_of=7324' );
    	array_push( $pages, '7324');
    
    	foreach ( $pages as $page ) {
    		$query_restrictions .= " AND doc != '" . $page->ID . "' ";
    	}
    	return $query_restrictions;	
    
    }
    
    add_filter ( 'relevanssi_where' , 'uf_search_filter' );
    Plugin Author Mikko Saari

    (@msaari)

    Correct, Relevanssi is not doing those WP MySQL queries that the filters filter, so no point using them. Relevanssi should provide enough filters to make most things possible, and suggestions for new filters are most welcome.

    Thread Starter Underscorefunk

    (@underscorefunk)

    The filters you’re talking about definitely did. They worked like charm! Thanks so much for the fantastic plugin!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘[Plugin: Relevanssi – A Better Search] Relevanssi ignores pre_get_posts post__not_in filtering’ is closed to new replies.