Home › Forums › ACF PRO › There can only be one field checked › Reply To: There can only be one field checked
The above solution was not working.
I think i found a better way of achieving what i was looking for:
function update_featured_post() {
global $posts;
global $post;
// Get other post marked as featured
$posts = get_posts([
// Array of posts to check
'post_type' => ['post', 'evento'],
'meta_key' => 'post_em_destaque',
'meta_value' => true,
'post__not_in' => [$post->ID]
]);
// Remove previous featured posts
if ( get_field( 'post_em_destaque' ) ) {
foreach( $posts as $p ) {
update_field('post_em_destaque', '0', $p->ID);
}
} return;
}
add_action('acf/save_post', 'update_featured_post', 20);
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.