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.
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
My issue is resolved now. Thank you!