Skip to content

Instantly share code, notes, and snippets.

@tripflex
Created May 11, 2017 14:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tripflex/cf5e51a0e9342535038926afce9498b5 to your computer and use it in GitHub Desktop.
Save tripflex/cf5e51a0e9342535038926afce9498b5 to your computer and use it in GitHub Desktop.
WP Job Manager Field Editor multiple value output as comma separated value instead of on new lines (</br>)
<?php
// DO NOT include the above <?php, there should ONLY be one at the top of your child theme's functions.php file
add_filter( 'field_editor_output_no_wrap_after', 'smyles_output_multiple_values_with_commas', 10, 6 );
function smyles_output_multiple_values_with_commas( $separator, $field_slug, $listing_id, $field_value, $args, $single_value ){
if( $field_slug !== 'your_meta_key' ){
return $separator;
}
return ', ';
}
@tripflex
Copy link
Author

<?php
//
//	CUSTOM FILTER TO ADD COMMA AFTER TAXONOMY OUTPUT FOR FIELD EDITOR
//
//

add_filter( 'field_editor_output_no_wrap_after', 'mysite_check_if_need_to_output_csv', 10, 6 );

function mysite_check_if_need_to_output_csv( $separator, $field_slug, $job_id, $field_values, $args, $single_value ){

	// ADD ANY ADDITIONAL META KEYS TO USE WITH COMMAS BELOW
	$csv_meta_keys = array( 'job_skill', 'qualification_tag' );
	
	// If meta key is not one of our meta keys from above, return the default separator
	if( ! in_array( $field_slug, $csv_meta_keys ) ) return $separator;

	$last_value = end( array_values($field_values) );
	
	if( ! empty( $single_value ) && $last_value !== $single_value ) {
		return ', ';
	} else {
		return '';
	}

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment