Support

Search results for ""

Sorry, no results found. Perhaps you would like to search the documentation?
All Topics
Jeff Gabrielson

Filter edit.php for a CPT so user can only see ‘mine’ mosts

Trying this again. Hi there! prior to installing the admin columns pro plugin I was using the following function to filter the edit.php page so that users of a certain role can only see those posts where they are they author. After installing admin columns pro it looks like that function no longer works and all users can see all posts created regardless of whether or not they’re the author. Are you able to recommend a way to do this while still keeping admin columns pro installed? Thanks!!

/**
 * Force the 'mine' view on the 'edit-post' screen
 */
function posts_for_current_author_tickets($query) {
    global $pagenow;
 
    if( 'edit.php' != $pagenow || !$query->is_admin )
        return $query;
 
    if( !current_user_can( 'edit_others_posts' ) ) {
        global $user_ID;
        $query->set('author', $user_ID );
    }
    return $query;
}
add_filter('pre_get_posts_tickets', 'posts_for_current_author_tickets');
3 years, 11 months ago
Stefan van den Dungen Gronovius
Developer

I don’t see a reason why it does not work anymore with our plugin activated. Maybe if one of the specific filters in our plugin also sets the author on the query, your code might be overwritten. But, as far as I know, we don’t do that.

I’m not familiar with the ‘pre_get_posts_tickets’ hook though, but I tried it myself with the default WordPress pre_get_posts hook which is an action btw and does not return the query and I was able to filter all my posts with Admin Columns activated. Maybe you can change it to pre_get_posts as well and add another post type check in your conditional.

3 years, 11 months ago

You must be logged in to reply to this topic.