How to show checkbox fields as comma-separated instead of a bullet list

By default, checkbox fields are displayed as a bulleted list. If you want to display them as a list of comma-separated values (CSV), you can do that with GravityView and a little code.

Before and After

Screenshot of a bulleted list with 'first choice' and 'third choice' as bullet items. This is the default look for checkbox fields:
Screenshot of a bulleted list with 'first choice, third choice' as a single text item.


And this is how the field values look once converted to CSV.

The required code

/**
 * Convert checkbox <ul> to CSV values
 *
 * @param string $output The current output.
 * @param \GV\Template_Context The template context this is being called from.
 */
add_filter( 'gravityview/template/field/checkbox/output', function( $output, $context ) {

	$value = $context->value;

	// If a checkbox value is '' (empty string), this removes it. If you want empty strings, remove the line below.
	$value = array_filter( $value, 'gravityview_is_not_empty_string' );

	return implode( ', ', $value );

}, 10, 2 );

Read here how to add these code samples to your website: Where to put code samples.

Did this answer your question? Thanks for the feedback There was a problem submitting your feedback. Please try again later.

Still need help? Contact Us Contact Us