[Resolved] remove relevanssi results from front end

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Tagged: 

This topic contains 1 reply, has 2 voices.

Last updated by Beda 9 months, 3 weeks ago.

Assigned support staff: Beda.

Author
Posts
#1340119

I am trying to: remove relevanssi results from front end

Link to a page where the issue can be seen: hidden link

I expected to see: no toolset posts that don't have public read access

Instead, I got: toolset posts that don't have public read access. i've inserted this code in functions.php per relevanssi support docs hidden link

If you want to keep the protected posts in the index, but only show them to users who are logged in, you can use a filter function like this:

add_filter( 'relevanssi_post_ok', 'rlv_search_exclude_protected', 10, 2 );
function rlv_search_exclude_protected( $allow, $post_id ) {
$post = get_post( $post_id );
if ( ! empty( $post->post_password ) ) {
$allow = false;
if ( is_user_logged_in() ) {
$allow = true;
}
}
return $allow;

#1340303

In Toolset Views, searches will not respect Toolset Access settings, this is a known "issue", but it's intended because the query just would be crashing too many use-cases.

Hence, a View should be shown/hidden in its entirety, if not results shouldn't be visible, or using Custom HTML Conditions, or similar approaches to hide/show content.

That should not be different in Relevannsis Search enhanced searches as the basis is still the same query (WP Query).

I see you found API provided by Relevannsi so to control what it outputs, which should be the correct way to go.
Toolset Access cannot control output in those queries, for performance reasons.

That said, you can suggest the feature to the Product Management, it is always possible, that our last findings are eventually not appropriate anymore, however it would require a new Feature (to make Access Rules respected in any query run on a site).

Please let me know if you need help adapting your Custom Code filter to listen to Toolset Access set rules, I can help with this . because right now, your code only would listen to password protection, which is not set by Access.
In case you need help with this, I will likely need access to a staging site or a very detailed step by step description of your rules applied in Toolset Access, and Relevannsi search, so I could replicate and provide the right solution to listen to Access settings.

Thank you!