Support

Account

Home Forums Backend Issues (wp-admin) Field Groups not showing for custom role

Solved

Field Groups not showing for custom role

  • Hi,

    We’re writting a site for a client who needs to give back end access to users.

    We have a custom post type of schools.

    I also have a custom role of school with the following caps

    	'read' => true,
    	'publish_posts' => false,
    	'publish_pages' => true,  
    	'edit_posts' => true,
    	'edit_published_posts' => true,
    	'delete_posts' => false,
    	'upload_files' => true

    I have created and added two field groups that contain image upload functions and selected them to only show when the Post Type is equal to schools.

    For the roles Super Admin and administrator. This works fine. However, The custom role of school is not displaying these field groups.

    Is there another capability that ACF requires in order to display the field groups?

    Cheers

  • Update,

    i’ve narrowed it down to the fact that i’m using this code to stop anyone who is logged in as a role of school being able to see anyone elses posts.

    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');

    If i remove that, the custom fields show fine.

    Any idea how to modify that code so it doesnt interfere with ACF?

  • Fixed.

    I’ve replaced the above filter with the following from here -> http://blog.rutwick.com/display-only-the-posts-authored-by-the-current-wp-user-on-the-posts-page-in-the-back-end.

    add_action('pre_get_posts', 'filter_posts_list');
    function filter_posts_list($query)
    {
        //$pagenow holds the name of the current page being viewed
         global $pagenow;
     
        //$current_user uses the get_currentuserinfo() method to get the currently logged in user's data
         global $current_user;
         get_currentuserinfo();
         
         //Shouldn't happen for the admin, but for any role with the edit_posts capability and only on the posts list page, that is edit.php
          if(!current_user_can('administrator') && current_user_can('edit_posts') && ('edit.php' == $pagenow)){
            //global $query's set() method for setting the author as the current user's id
            $query->set('author', $current_user->ID);
            }
    }
  • Thanks for this.
    I had the very same problem.
    One question though: how would I add a filter to do the exact same thing with the Media Library?

Viewing 4 posts - 1 through 4 (of 4 total)

The topic ‘Field Groups not showing for custom role’ is closed to new replies.