Skip to:
Content
Pages
Categories
Search
Top
Bottom

Excluding content from search pagination using Premise access levels


  • LeoBCpt
    Participant

    @leobcpt

    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?

Viewing 2 replies - 1 through 2 (of 2 total)
  • You are going to have more issues than just search and search pagination if Premise is only detecting by forum category and/or post_parent in wp_postmeta.

    I expect you will also find them turn up via widgets, shortcodes and custom registered views.

    If Premise was detecting by each off bbPress’ post types, forum, topic and reply specifically rather than forum category alone you would find that it would also filter these results correctly from search also alleviating your pagination issue whilst also making sure they didn’t turn up in via widgets, shortcodes or custom views.


    LeoBCpt
    Participant

    @leobcpt

    Hi Stephen

    Thanks for coming back to me.

    Do you think if I add the access levels to the postmeta of forums, topics and replies that this will work correctly? How would I get BBPress to automatically add the meta to new posts?
    Would I also need to add a search filter after the postmeta is added?

Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.
Skip to toolbar