The only way I can think of to do it would be using the save_post
action hook. Since your article isn’t being saved through AJAX, and only when you actually save the post, that would be the best place, in my opinion.
I honestly haven’t written a lot of error messages, so this might be wonky and probably won’t work out of the gate, but I started with this article from SitePoint.
add_action( 'save_post', 'my_save_post_function' );
function my_save_function( $post_id ) {
$error = false;
$featured = get_posts(array(
'meta_query' => array(
array(
'key' => 'featured_article',
'compare' => '=',
'value' => '1'
)
)
));
if ( count($featured) > 3 ) {
$error = new WP_Error('too_many_featured_articles', 'There are too many featured articles.');
// You could use this error to list the titles and links to edit all of the other current featured articles.
}
if ($error) {
// Here is where you would unset the ACF field, if you wanted.
}
return true;
}
This isn’t meant to get you through the whole thing, but hopefully it’s a good starting point for you.