Excluding content from search pagination using Premise access levels
-
Hi there
Using bbPress Version 2.3.2
We’ve got Premise member access module installed. It manages access to posts by adding meta tags to the wp_postmeta table. We then check member access levels against these meta tags to see if the user can access a post.We also use these member access levels to restrict access to our forums. Unfortunately the member access tags are only added to the forum categories and parents, and not to the individual replies and posts.
This means that restricted posts turn up in search results, and have to be excluded by checking the user access level against that of the forum category or parent.
I’ve managed to exclude the posts from the search results, by adding the following lines of code I found in these forums to the loop in loop-search.php just before get_template_part is called:
$parent = array_reverse(get_post_ancestors($post->ID)); // get an array of all the parent pages in order from most distant to closest. $first_parent = get_page($parent[0]); //get the first page in the array, which is the most distant parent $int = apply_filters(‘the_ID’, $first_parent->ID); //filter the $first_parent to get only the wordpress page/post ID, which is an integer like 49 or 565. store it as a variable $int //Skip post if user can't access it. if (!IQS_can_user_access_post($int)) { continue; }
This code works, however the pagination results still show for all the excluded posts.
I’ve been trying to figure out how to modify the bbpress()->search_query results but I’m not very good with PHP.
Any advice on how I can exclude posts from a search query or fix my pagination?
- You must be logged in to reply to this topic.