Hi I'm using this code to make only the admin see all the posts and editor users can see only their own added posts, but it is also restricts custom feilds form showing when I add or edit any post using an editor user (The fields inside the post page), how can I exclude the custom fields so all the users including editors will be able to see them on each post page.
add_shortcode('pledge_count', 'get_pledge_count');
add_filter( 'pre_get_posts', 'fb_pre_get_posts' );
function fb_pre_get_posts( $queryobj ) {
if(is_admin()){
if ( ! current_user_can( 'edit_users' ) )
$queryobj->query_vars[ 'author' ] = get_current_user_id();
}
return $queryobj;
}
I solved the issue and posting it in case someone else facing this.
This is solved by specifying the post types that I'm going to give the access to the user created it:
add_shortcode('pledge_count', 'get_pledge_count');
add_filter( 'pre_get_posts', 'fb_pre_get_posts' );
function fb_pre_get_posts( $queryobj ) {
switch($query->query_vars['post_type']){
case 'attachment': // Media library
$queryobj->query_vars[ 'author' ] = get_current_user_id();
break;
case 'post': // Posts
$queryobj->query_vars[ 'author' ] = get_current_user_id();
break;
case 'page': // Pages
$queryobj->query_vars[ 'author' ] = get_current_user_id();
break;
} // switch post_type
return $queryobj;
}