Support

Search results for ""

Sorry, no results found. Perhaps you would like to search the documentation?
All Topics
Jason Bullock

Checkbox True/False in Repeater not Exporting Values

I have a true/false ACF field in a repeater that shows in admin columns (Advanced Custom Fields/Repeater/Subfield/checkbox name). It displays as a green check if true and a red X if not true. This is great to view but when I export, there are no values exported. Is there a way to export whether it’s true or false? It would be nice to generate a csv with these values since we need to make decisions based on items that have any repeater values of false.

2 years, 7 months ago
Stefan van den Dungen Gronovius
Developer

The only way to make this work at the moment is by using a hook to alter the exported value for your ACF field column. You may need to tweak it a bit and you need to fill in your sub key for ‘your_sub_key’ but this give you a 1 or 0 for the checked values in the repeater:

add_filter( 'ac/export/value', function ( $value, \AC\Column $column, $id ) {
	if ( $column instanceof ACA\ACF\Column ) {
		$field = $column->get_field();

		if ( $field instanceof ACA\ACF\Field\Repeater ) {
			$values = [];
			$sub_field = ACA\ACF\API::get_field( $column->get_setting( 'sub_field' )->get_value() );

			if ( $sub_field['key'] === 'your_sub_key' ) {
				foreach ( (array) $column->get_raw_value( $id ) as $single_value ) {
					$values[] = is_array( $single_value ) && isset( $single_value[ $sub_field['key'] ] ) ? $single_value[ $sub_field['key'] ] : '';
				}
			}
		}

		$value = implode( ',', $values );
	}

	return $value;
}, 10, 3 );

2 years, 7 months ago

You must be logged in to reply to this topic.