WordPress.org

Ready to get started?Download WordPress

Forums

Members
Filtering pre_get_posts with members (1 post)

  1. nimmolo
    Member
    Posted 1 year ago #

    Currently I'm using a function from the plugin:

    members_can_current_user_view_post()

    within a customized loop to "skip" current post_ID if current user does not have permission to read it.

    function custom_loop() {
    
            while ( have_posts() ) : the_post();
    
                global $current_user;
                global $post;
    
                if ( function_exists('members_can_current_user_view_post') && members_can_current_user_view_post( get_the_ID() ) ) {
                // the loop here

    That works, but the problem with doing it that way is that occasionally (like now) the entire first page-worth of posts is private (all 5 most recent posts). For a nonsubscriber, the blog page query returns no posts, instead of returning the 5 next most recent posts the current user can view, which is what i want.

    What I am trying to do is filter the posts via pre_get_posts instead, but I don't get how this function can be used to set the permissions query var ('perm'), since the desired effect is governed by that query var. Should I be setting up a new query var?

    Sorry for the ignorance implicit in this question.
    I have searched the forum and have not found an analogous use of pre_get_posts.

    By the way ideally I want it to affect most queries, including nav menu queries.

    http://wordpress.org/extend/plugins/members/

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic