• This plugin should be unique in its kind

    But I need something else
    I need an option or code that allows each user in each role to see only their own posts, and completely hide the posts of others, even in search results (without any messages or bookmarks)

    **More details:**
    The user has to log in to get the content, and when he logs in he only sees his posts (as if there are no other posts on the website)

    Any help would be appreciated

    • This topic was modified 2 years, 4 months ago by hamed.
Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Condless


    Hi Hamed,
    The following code will display the users only their own posts (applied on any post type):

    add_action( 'pre_get_posts', 'wp_restrict_to_owner' );
    function wp_restrict_to_owner( $query ) {
    	if ( ! is_admin() && ! current_user_can( 'manage_options' ) ) {
    		$query->set( 'author', is_user_logged_in() ? get_current_user_id() : '999999' );
    Thread Starter hamed


    Thanks for the quick reply

    I want all pages to be excluded (show for all)
    Only hide other users’ posts

    Plugin Author Condless


    Customization will be required, please contact via email.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Restrict posts based on user in each role’ is closed to new replies.