Ok, well I’ve got something that works now. But as I am a newbie to ACF snippets, I would be very grateful if someone would check this over and let me know how I might improve it. Thanks!
/* Fill empty ACF fields with "blank" so TablePress can hide them */
function set_empty_value( $post_id ) {
if ( 'product' != get_post_type($post_id) ) {
return;
}
$fields = get_fields();
if( $fields ) {
foreach ( $fields as $name => $value ) {
if ( $value == '' ) {
$value = "blank";
update_field( $name, $value );
}
}
}
}
add_action('acf/save_post', 'set_empty_value', 10, 1 );
Thank you, John!
This thread seems to be sticking, so the specific thread I am trying to activate is titled “Set default value for all empty fields on save”.
I’m having the same issue. I created a topic called “Set default value for all empty fields when saving”. But as the OP describes, I cannot find my thread in my profile or the topic board, nor can I repost same. Can someone help me activate my thread? Thanks.
Ok, I figured out that this could be achieved by resetting the value to false (no) after a product is published. That way the duplicate is loaded with No selected.
This code works, but please let me know if I can improve upon it. Thanks.
function reset_product_readiness_after_publish( $post_id ){
$value = "0";
update_field('field_30705432c7518', $value, $post_id);
}
add_action('acf/save_post', 'reset_product_readiness_after_publish', 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.