@pamplemousse instead of using acf/validate_save_post
as the hook use acf/validate_value
unstested but let me know
I am not sure why it has yet to be fixed in core,
Also the $acf = false;
is a oversight, I have a slighlty different implementation myself and forgot to remove when copying it over
Let me see if I can find a work around for you 🙂
You can run a query for the unique_id
with the below:
$existingPost = get_posts( array(
'meta_key' => 'unique_id',
'meta_value' => '555555',
));
if($existingPost){
$my_post['ID'] = $existingPost->ID;
$post_id = wp_update_post( $my_post );
}else{
$post_id = wp_insert_post( $my_post );
}
I have found a workaround here
I am not sure why this is still an issue and can only apologise for not requiring (pardon the pun) this feature earlier.
The issue is due to the Validation not accepting anything but directly assigned fields, it ignores acf_blocks_{UNIQUE_ID}.
So… Until ACF Dev updates the core code, add the below snippet to functions.php as a workaround. DEMO
add_action( 'acf/validate_save_post', '_validate_save_post', 5 );
function _validate_save_post() {
// bail early if no $_POST
$acf = false;
foreach($_POST as $key => $value) {
if (strpos($key, 'acf') === 0) {
if (! empty( $_POST[$key] ) ) {
acf_validate_values( $_POST[$key], $key);
}
}
}
}