exclude members only content
-
Hi Mikko,
A project I am working on is using Relevanssi Premium for it’s search functionality which is working great but the customer wants to exclude members only content and attachments with specific categories from search results for non-logged in users and for this content to be searchable for logged in users.
I’m using the
relevanssi_hits_filter
but having read a bit more, it looks like I might need to use therelevanssi_post_ok
also. How can I use the post_ok filter with hits_filter?
The code I have at the moment (which doesn’t check content permissions yet) is this:add_filter('relevanssi_hits_filter', 'filter_members_only'); function filter_members_only($hits){ if(is_user_logged_in()){ return $hits; } else { $members_content = array(); $public_content = array(); foreach ($hits[0] as $hit) { $tags = get_the_tags($hit->ID); if(is_array($tags)){ foreach ($tags as $tag) { if($tag->term_id == 143){ $members_only = true; break; } } $members_only ? array_push($members_content, $hit) : (array_push($public_content, $hit)); } } $hits[0] = $public_content; return $hits; } }
Currently, the code above returns all results for the logged in user but seems to have unexpected results for the user without login.
Any pointers would be greatly appreciated.
Thanks in advance.
- The topic ‘exclude members only content’ is closed to new replies.