@OsakaWebbie : take a look at this two links:
https://snipt.net/raw/6d5b0a6e8fb04a4febfbc78cfc1805eb/?nice
Regards,
Thanks emcniece! You made me see the light! 😉
Yes, this works for me. The cache made me crazy!
add_action( 'pre_get_posts', 'filtre');
function filtre($query) {
global $user_ID;
//global $current_user;
if( !is_admin() ) {
$query->set('author', $user_ID);
//$query->set('author',$current_user->id);
}
return $query;
}
Now I’m gonna try to filter the media, taxonomies and ACF. Will see if there’s a problems!
It seems was a cache problem!!
And to continue with the restriction.
What about filter the media?
Something like this, but not working yet
function ik_eyes_only( $wp_query ) {
if ( strpos( $_SERVER[ 'REQUEST_URI' ], '/wp-admin/upload.php' ) !== false || strpos( $_SERVER[ 'REQUEST_URI' ], '/wp-admin/edit.php' ) !== false ) {
if ( !current_user_can( 'level_5' ) ){
global $current_user;
$wp_query->set( 'author', $current_user->id );
}
}
}
add_filter('parse_query', 'ik_eyes_only' );
Thanks a lot!
I’m trying now.
user1 -> user_id=3
user2 -> user_id=5
Have you create a CPT row with user1, and log into with user2, and you don’t see the CPT row?
Did you mean this?
$query->set('author', 5);
Or you see the CPT row but you can’t edit?
Because I have various CPT, and with a CPT that I create automatically, I see de results but I can’t edit, but with a CPT that I create manually, I can edit the result. What I’m doing wrong?
Hi,
not working. 🙁
Scenario:
I have 2 users (user1,user2), Rol Author.
The user1 has created a CPT restaurant called rest1, and when I log into a Backend with user2 I can edit rest1. :S
I’ve tried all the combinations:
add_action( 'pre_get_posts', 'filtre');
function filtre($query) {
//tried option 0
//global $user_ID;
//tried option 1
//global $current_user;
if( !is_admin() ) {
$query->set('author', get_current_user_id());
//tried option 0
//$query->set('author', $user_ID);
//tried option 1
//$query->set('author',$current_user->id);
//tried option 2
//$user = wp_get_current_user();
//$query->set('author_name', $user->data->user_nicename );
}
return $query;
}
I don’t know whatelse.
Help please!
Thanks!
Interesting, but this is only for the ACF post object (necessary too in my project).
What about the list of posts?
Thanks for the reply!
Finally solved!
Thanks!
Hi,
in the post view in backend.
I add a screenshot.
Because there are a long list of products, it could be practic to see the restaurant of this product or filter for a particular restaurant.
The product has a ACF type Post Object restaurant that is assigned in every product with his description, image, price, discount, etc.
Thanks!
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.