Support

Account

Home Forums Backend Issues (wp-admin) Not compatible with this code? Reply To: Not compatible with this code?

  • Since I’m using it for the post type “course”, I changed the post_type=post into post_type=course.

    However, the count still doesn’t work (it still counts everything).

    Also, the 1st part of your code (that you last posted) doesn’t work (to show only the authors content) – while an earlier example of you did work – so I used the code below for the first part and added the “Fix post counts” count only.

    What I’m currently using (working code).

    // So authors can only see their own content (e.g. courses etc)
    function posts_for_current_author($query) {
    	
    	if( !$query->is_admin )
    		return $query;
    		
    	$screen = get_current_screen();
    	
    	if ($screen->base === 'post')
        		return $query;
    	
    	if( !current_user_can( 'activate_plugins' ) ) {
    		global $user_ID;
    		$query->set('author', $user_ID );
    		
    	}
    	return $query;
    	
    	
    }
    
    add_filter('pre_get_posts', 'posts_for_current_author');

    I haven’t been able to get the count correct, see http://d.pr/i/Ijhs.