Skip Navigation

[Resolved] Only allow users to see their own posts on wordpress admin

This support ticket is created 2 years, 7 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Karachi (GMT+05:00)

Author
Posts
#2313489

Hello!
I would like to know if it is possible to filter the posts a user sees at wordpress admin. For example I want users of type simpleusers to only be able to see their own posts of a specific post type. Also, is it possible to bind a user with a taxonomy and only see posts that are connected to a specific taxonomy (e.g. only see posts with taxonomy Countries = Greece).
Thanks in advance.

#2313919

Hi,

Thank you for contacting us and I'd be happy to assist.

You can use the Toolset Access plugin, to control which user role can view, edit and publish which type of posts:
https://toolset.com/course-lesson/setting-access-control/

Using this approach the posts from other authors will still be available in the admin area list, even though they won't be editable.

To hide the posts from other authors in the admin area list, you can then use the code snippet from this tutorial:
hidden link


function posts_for_current_author($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', 'posts_for_current_author');

The above code snippet can be included through either Toolset's custom code feature ( ref: https://toolset.com/documentation/adding-custom-code/using-toolset-to-add-custom-code/ ) or through the active theme's "functions.php" file.

Similarly, to bind the user to a particular taxonomy term, you can include a user custom field with the users that store the target taxonomy term's slug as a value.

You can then customize the code snippet shared above to include the taxonomy query to show only posts associated with that term.
( example: https://wordpress.stackexchange.com/a/35263 )

I hope this helps and for more personalized assistance around custom code, you can also consider hiring a professional from our list of recommended contractors:
https://toolset.com/contractors/

regards,
Waqar

#2314263

My issue is resolved now. Thank you!

This ticket is now closed. If you're a Toolset client and need related help, please open a new support ticket.