Đặt term_meta thực trên các trường tùy chỉnh điều khoản ACF khi cập nhật / tạo

/**
 * ACF fix for term meta
 * replace {{custom_term_meta_x}} by your ACF term custom field name
 * TODO: loop over all term_meta to auto-generate filters
 *
 * https://support.advancedcustomfields.com/forums/topic/how-to-use-wp-term-meta-on-acf-the-easy-way/
 */
function acf_update_term_meta( $value, $post_id, $field ) {
	$term_id = (int) filter_var( $post_id, FILTER_SANITIZE_NUMBER_INT );
	if ( $term_id > 0 ) {
		update_term_meta( $term_id, $field['name'], $value );
	}

	return $value;
}
add_filter( 'acf/update_value/name={{custom_term_meta_1}}', 'acf_update_term_meta', 10, 3 );
add_filter( 'acf/update_value/name={{custom_term_meta_2}}', 'acf_update_term_meta', 10, 3 );

function acf_load_term_meta( $value, $post_id, $field ) {
	$term_id = (int) filter_var( $post_id, FILTER_SANITIZE_NUMBER_INT );
	if ( $term_id > 0 ) {
		$value = get_term_meta( $term_id, $field['name'], true );
	}

	return $value;
}
add_filter( 'acf/load_value/name={{custom_term_meta_1}}', 'acf_load_term_meta', 10, 3 );
add_filter( 'acf/load_value/name={{custom_term_meta_2}}', 'acf_load_term_meta', 10, 3 );