Support

Account

Forum Replies Created

  • 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 );
  • 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);
Viewing 5 posts - 1 through 5 (of 5 total)