Skip to main contentSkip to footer

Relevanssi has a conflict with User Access Manager plugin. Both plugins attach to the same `the_posts` filter hook with the same priority, and if UAM runs after Relevanssi, it may cause some issues, like missing excerpts or even broken search results pages.

The solution seems simple, however: at least in the one case I’ve run into so far, things started working after I moved Relevanssi to a slightly later priority, so it runs after UAM. That’s easy to do, just add the following code to your theme functions.php:

add_filter('after_setup_theme', 'rlv_move_to_later_priority');
function rlv_move_to_later_priority($priority) {
	remove_filter('the_posts', 'relevanssi_query');
	add_filter('the_posts', 'relevanssi_query', 11);
}

Update 19.1.2021: This is no longer necessary, as Relevanssi runs on `posts_pre_query` hook now.

Your account

Not logged in. Log in to see your license details.

Search

Popular Resources

Chamber Dashboard Business Directory
The Chamber Dashboard Business Directory plugin has a business directory search that’s not compatible with Relevanssi. To disable Relevanssi in…
Adding a custom field filter in the search

…! empty( $query->query_vars[‘colour’] ) ) { $meta_query = array( array( ‘key’ => ‘colour_field’, ‘value’ => $query->query_vars[‘colour’], ‘compare’ => ‘=’, ), ); $query->set( ‘meta_query’, $meta_query ); } return $query; } If you need to have multiple meta fields in the same search, you must add them to the same meta_query –……} If you need to have multiple meta fields in the same search, you must add them to the same meta_query – you can only have one. WP_Query documentation has a good example of what that looks like, so take a look at that if you need multiple custom fields….Adding a custom field filter in a Relevanssi search takes a little bit of programming, because the filter needs to create a meta_query that Relevanssi understands. Let’s assume we have some colour information in a custom field that’s called colour_field, and we want to use that to filter the search…

Related Posts:

Comment Section:

5 Comments. Leave new

  • We are still having the same issue over UAM vs Relevanssi after we tried the above solution. Is there any other way to rectify this?

    Reply
    • That fix doesn’t even do anything anymore, Relevanssi is now already by default on priority 99.

      What kind of problems you are having with UAM and Relevanssi? I tried it now and everything seems to work without problems. Relevanssi doesn’t respect the UAM restrictions and will show the posts in search results (but of course you can’t see the actual post), but I’ll fix that in the next version.

      Reply
      • Hi Mikko,
        Thanks for your reply.
        Our issue is UAM posts are still displaying in the search result.
        for eg,
        this post (https://www.parkwaycancercentre.com/from-survivor-to-volunteer/) should only visible to the login user, but its displaying in search result (https://www.parkwaycancercentre.com/?s=FROM+SURVIVOR+TO+VOLUNTEER).
        Thanks

        Reply
        • Ok, that isn’t even supposed to work in the current version, the current version doesn’t have any UAM compatibility built in.

          This will be fixed in the next version, but meanwhile you can add this to your theme functions.php:

          add_filter( 'relevanssi_post_ok', 'rlv_uam_post_ok', 11, 2 );
          function rlv_uam_post_ok( $post_ok, $post_id ) {
          	// User Access Manager.
          	global $userAccessManager; // phpcs:ignore WordPress.NamingConventions.ValidVariableName
          	if ( isset( $userAccessManager ) ) { // phpcs:ignore WordPress.NamingConventions.ValidVariableName
          		$type    = relevanssi_get_post_type( $post_id );
          		$post_ok = $userAccessManager->getAccessHandler()->checkObjectAccess( $type, $post_id ); // phpcs:ignore WordPress.NamingConventions.ValidVariableName
          	}
          	return $post_ok;
          }

          This should fix the problem.

          Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

Fill out this field
Fill out this field
Please enter a valid email address.
You need to agree with the terms to proceed