Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter duncan

    (@flowevd)

    Perhaps I could create a dummy user with Level #2 access and pass them into get_unavailable_singular_ids_with_ccaps( $user )
    then use those ids in post__not_in?

    EDIT That won’t work…. I need levels, not custom capabilities

    Thread Starter duncan

    (@flowevd)

    OK, here’s how to do it (only works for posts, and not tested yet).

    function get_s2_restricted_posts_by_access_level( $level ) {
        $ids = array();
        $s2_options = get_option( 'ws_plugin__s2member_options' );
        for( $i = 0; $i <= $level; $i++ ) {
            if( $s2_options["level_$i_posts"] ) {
                $ids = array_merge( $ids, explode( ',', $s2_options["level_$i_posts"] ) );
            }
        }
        return $ids;
    }

    then

    $posts_visible_for_level_2 = get_s2_restricted_posts_by_access_level(2);
    get_posts( [ 'post__in' => $posts_visible_for_level_2 ] );

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Query posts by access level’ is closed to new replies.