Support

Account

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);