Hello, together.
I’m new with ACF and need your help with following issue:
I’ve created a custom post type with my own meta boxes. With ACF I add two special boxes like geo locator and image upload. Everything works fine until my user has the role administrator.
The reason is a short code which hides all custom posts from other users than the one who is logged in, in the overview list.
The code is:
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;
}
If I delete the line “$query->set(‘author’, $user_ID);” I see all ACF meta boxes on the edit page, but also all entries from all users in the list.
Do someone has any idea how I can get both working together?
Thanks a lot for your help in advance!
add_filter( 'posts_where', 'creator_posts' );
function creator_posts( $where ){
global $wpdb, $pagenow, $current_user;
if ( is_admin() && $pagenow=='edit.php' && $current_user->user_login != 'admin') {
$where .= "AND (".$wpdb->posts.".post_author = '".$current_user->ID."' )";
}
return $where;
}
you can also add any other statements to IF block for example
VoiD2008, you made my day!
I changed the if statement a little bit to
if ( (is_admin() && $pagenow=='edit.php') && !current_user_can( 'update_core' )) {
So I don’t have to know the name of the user. Only if the user has a very high privileg (like update_core) I will show him/her the entire list.
Thanks again for this quick and very good answer!
Yep your statement better =) You are welcome =)