Relevanssi - A Better Search
User Access Manager restricting excerpt when not logged in (1 post)

  1. danteand
    Posted 3 years ago #

    I am using Relevanssi on a site which is also using User Access Manager. I wanted Relevanssi to show links to protected pages in the search results, but to show a please log in message instead of the excerpt. I created this custom excerpt function and added it to the theme's functions.php file. I use this function in my search.php template:

    function custom_relevanssi_the_excerpt() {
        global $post;
        global $userAccessManager;
    	if (isset($userAccessManager)) {
    		$postId = $post->ID;
    		$uamAccessHandler = $userAccessManager->getAccessHandler();
    		$boolean = $uamAccessHandler->checkObjectAccess('post', $postId);
    	} else {
    		$boolean = true;
        if (post_password_required($post)) {
    		echo __('There is no excerpt because this is a protected post.');
    	} elseif ($boolean) {
    	    echo "<p>" . $post->post_excerpt . "</p>";
    	} else {
    		echo __('<p>This content is in the member area. Please <a href="/member-login/">log in</a> to see it.</p>');


Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Relevanssi - A Better Search
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic

  • RSS feed for this topic
  • Started 3 years ago by danteand
  • This topic is not a support question
  • WordPress version: 3.4.1