Home › Forums › Backend Issues (wp-admin) › Not compatible with this code? › Reply To: Not compatible with this code?
Hi
Interestingly only a day later than the last post I came looking for an answer to exactly the same question. I seem to have solved the problem, well at least for myself I have in this way…
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( 'moderate_comments' ) ) {
global $user_ID;
$query->set('author', $user_ID );
}
return $query;
}
Essentially this checks to see if you are in admin
Then the critical bit for ACF it looks to see if you are editing a page which is the screen->base === ‘post’ bit. That will return the standard query since the mod to user_ID in the query loses the ACF fields.
Like I said this works here and I should be grateful if you can let me know if it works for you too.
By the way I have additional code to change the headings on the list of posts since it shows all and published even though you can’t see them.
All the best
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!
Are you building WordPress sites with ACF and @BeaverBuilder, and wanted to use your ACF Blocks in both the block editor and Beaver Builder?
— Advanced Custom Fields (@wp_acf) May 10, 2023
The BB team recently added support for using ACF Blocks in Beaver Builder. Check it out 👇https://t.co/UalEIa5aQi
© 2023 Advanced Custom Fields.
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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.