WordPress.org

Ready to get started?Download WordPress

Forums

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

  1. danteand
    Member
    Posted 1 year 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>');
    	}
    }

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

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

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