@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);
}
}
}
}
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!
2022 was a big year for Advanced Custom Fields, with more capabilities, a new generation of ACF Blocks, a refreshed UI, and a new home. Our year in review post looks at advancements we’ve made and offers a glimpse of the future.
— Advanced Custom Fields (@wp_acf) January 6, 2023
https://t.co/HahJUCcyH4
© 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.