WordPress.org

Ready to get started?Download WordPress

Forums

Display logged in user posts only, displaying counts for all posts (1 post)

  1. haagsekak
    Member
    Posted 1 year ago #

    I am using a hack I found that only displays the posts and images for a logged in user instead of all users, but the comments are still not working. However there is an item count just below the page title that includes a count for all posts and images on the site instead of just the logged in user.

    Is there a custom fix for that or can someone provide another hack for that? Below is the code I used in my functions.php so maybe someone might be able to expand the code to include also comments?

    function posts_for_current_author($query) {
    	global $user_level;
    
    	if($query->is_admin && $user_level < 5) {
    		global $user_ID;
    		$query->set('author',  $user_ID);
    		unset($user_ID);
    	}
    	unset($user_level);
    
    	return $query;
    }
    add_filter('pre_get_posts', 'posts_for_current_author');

    Thank you for your help.

Topic Closed

This topic has been closed to new replies.

About this Topic