Title: Search Results Yield Draft Posts
Last modified: January 7, 2020

---

# Search Results Yield Draft Posts

 *  Resolved [livingmiracles](https://wordpress.org/support/users/livingmiracles/)
 * (@livingmiracles)
 * [6 years, 4 months ago](https://wordpress.org/support/topic/search-results-yield-draft-posts/)
 * Hello,
 * We recently discovered that when Subscribers/members of our site do a search 
   on the frontend, the search results include posts that are drafts (i.e., not 
   published)—that shouldn’t be happening. However, when you actually click on the
   draft post in the search result, you get a “Page not found” error page. In conjunction
   with Relevanssi, we’re using a premium plugin called, “Restrict Content Pro” 
   which is a membership plugin that restricts content of the site based on the 
   visitor’s membership level.
 * We currently have three drafts on the site. They all have the same Restrict Content
   Pro settings, just like the published posts—and of course, they all have the 
   same Relevanssi settings since they’re global.
 * Here are some screenshots:
    • [https://ibb.co/JF90SCR](https://ibb.co/JF90SCR)•
   [https://ibb.co/pZrNzj9](https://ibb.co/pZrNzj9)
 * We don’t know when this issue started but we know for sure that it wasn’t always
   like this. We’ve had the site setup in this way with Relevanssi and Restrict 
   Content Pro since 2015.
 * For troubleshooting, we’ve tried deactivating all other plugins except Relevanssi
   and Restrict Content Pro and also setting the theme to a default WordPress theme.
   Even with this, the issue still occurs. However, we’ve noticed that if we disable
   one plugin or the other (Relevanssi or Restrict Content Pro), then the draft 
   posts don’t show up in the search results.
 * Do you have any suggestions for troubleshooting and fixing this issue?
 * Thank you,
    Nicolas from Living Miracles
 * The page I need help with: _[[log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Fsearch-results-yield-draft-posts%2F%3Foutput_format%3Dmd&locale=en_US)
   to see the link]_

Viewing 5 replies - 1 through 5 (of 5 total)

 *  Plugin Author [Mikko Saari](https://wordpress.org/support/users/msaari/)
 * (@msaari)
 * [6 years, 4 months ago](https://wordpress.org/support/topic/search-results-yield-draft-posts/#post-12302774)
 * Try adding this to your theme functions.php:
 *     ```
       add_action( 'plugins_loaded', 'rlv_rcp_fix' );
       function rlv_rcp_fix() {
           remove_filter( 'relevanssi_post_ok', 'relevanssi_restrictcontentpro_compatibility', 10, 2 );
       }
   
       add_filter( 'relevanssi_post_ok', 'rlv_restrictcontentpro_compatibility', 10, 2 );
       function rlv_restrictcontentpro_compatibility( $post_ok, $post_id ) {
       	$status = relevanssi_get_post_status( $post_id );
       	if ( 'publish' === $status ) {
       		$post_ok = rcp_user_can_access( get_current_user_id(), $post_id );
       	}
       	return $post_ok;
       }
       ```
   
 * Does that solve the problem?
 *  Thread Starter [livingmiracles](https://wordpress.org/support/users/livingmiracles/)
 * (@livingmiracles)
 * [6 years, 4 months ago](https://wordpress.org/support/topic/search-results-yield-draft-posts/#post-12305345)
 * Hi Mikko,
 * Thank you for the suggestion to try the code in the functions.php file. We tried
   it out but, unfortunately, it did not fix the issue for us. However, we had also
   written to Restrict Content Pro yesterday about this same issue and they replied
   with the following:
 * > I’ve looked into this and it’s an issue with Relevanssi’s Restrict Content 
   > Pro integration. When determining whether or not a post should be visible, 
   > they normally check things like if the post is a draft, etc. However, in their
   > RCP integration, they just check RCP’s [rcp_user_can_access()](https://docs.restrictcontentpro.com/article/1648-rcp-user-can-access)
   > function and use that as the master determination of whether or not a post 
   > should appear in the archive. However, that function of ours ONLY checks restriction
   > permissions. So essentially what’s happening here is that if a user has RCP’s
   > permission to view a post, then Relevanssi is including it. They’re not combining
   > that with their normal checks, which is what they should be doing.
   > If you’d like to pass this information along to them, the problem is in their
   > file relevanssi/lib/compatibility/restrictcontentpro.php. Their function is
   > currently like this:
   >     ```
   >     function relevanssi_restrictcontentpro_compatibility( $post_ok, $post_id ) {
   >     	$post_ok = rcp_user_can_access( get_current_user_id(), $post_id );
   > 
   >     	return $post_ok;
   >     }
   >     ```
   > 
   > One possible fix would be to adjust it like so:
   >     ```
   >     function relevanssi_restrictcontentpro_compatibility( $post_ok, $post_id ) {
   >     	if ( ! $post_ok ) {
   >     		return $post_ok;
   >     	}
   > 
   >     	$post_ok = rcp_user_can_access( get_current_user_id(), $post_id );
   > 
   >     	return $post_ok;
   >     }
   >     ```
   > 
   > That makes it so if the user doesn’t meet the BASE requirements (checking draft
   > status, etc.) then the user can’t view it. If the user does meet those requirements,
   > then it proceeds to check RCP content restrictions and use those.
 * We tried out this code ourselves in this /wp-content/plugins/relevanssi/lib/compatibility/
   restrictcontentpro.php file and it worked immediately—draft posts no longer showed
   up in search results.
 * Can this fix please be implemented in the next Relevanssi plugin update and, 
   if so, is there an ETA on that update? In the meantime, we’ll simply keep Restrict
   Content Pro’s fix in the restrictcontentpro.php file. But, of course, this is
   not ideal as we’ll need to manually re-implement this fix after each Relevanssi
   update if the fix is not incorporated.
 * Thank you!
    Nicolas from Living Miracles
 *  Plugin Author [Mikko Saari](https://wordpress.org/support/users/msaari/)
 * (@msaari)
 * [6 years, 4 months ago](https://wordpress.org/support/topic/search-results-yield-draft-posts/#post-12306715)
 * This fix will be incorporated in the next version. Don’t know when that is, but
   since you have a working fix and won’t have to worry about the updates, that 
   shouldn’t be a problem.
 * (Their fix does essentially the same thing my fix does, so strange that that 
   didn’t work.)
 *  Thread Starter [livingmiracles](https://wordpress.org/support/users/livingmiracles/)
 * (@livingmiracles)
 * [6 years, 4 months ago](https://wordpress.org/support/topic/search-results-yield-draft-posts/#post-12310323)
 * Hi Mikko,
 * That’s great, thank you!
 * Nicolas from Living Miracles
 *  [mail2technerd](https://wordpress.org/support/users/mail2technerd/)
 * (@mail2technerd)
 * [6 years, 3 months ago](https://wordpress.org/support/topic/search-results-yield-draft-posts/#post-12322917)
 * Hi Mikko
    I have been facing the same issue. Let me explain. I have 321 posts
   where 320 is published and 1 is draft. But when I search I can see the result
   is showing 321 posts. I tried with the solution in this post but got error. Uncaught
   Error: Call to undefined function rcp_user_can_access()

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Search Results Yield Draft Posts’ is closed to new replies.

 * ![](https://ps.w.org/relevanssi/assets/icon-256x256.png?rev=2025044)
 * [Relevanssi - A Better Search](https://wordpress.org/plugins/relevanssi/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/relevanssi/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/relevanssi/)
 * [Active Topics](https://wordpress.org/support/plugin/relevanssi/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/relevanssi/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/relevanssi/reviews/)

 * 5 replies
 * 3 participants
 * Last reply from: [mail2technerd](https://wordpress.org/support/users/mail2technerd/)
 * Last activity: [6 years, 3 months ago](https://wordpress.org/support/topic/search-results-yield-draft-posts/#post-12322917)
 * Status: resolved