Created
March 13, 2018 21:44
-
-
Save tripflex/57be4aaf810a0b0f9d655a99cab3e91b to your computer and use it in GitHub Desktop.
Output CSV for instead of line break (<br/>) for job_category with WP Job Manager Field Editor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// | |
// CUSTOM FILTER TO ADD COMMA AFTER TAXONOMY OUTPUT FOR FIELD EDITOR | |
// | |
// | |
add_filter( 'field_editor_output_no_wrap_after', 'smyles_output_csv_for_job_category', 10, 6 ); | |
function smyles_output_csv_for_job_category( $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_category' ); | |
// 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) ); | |
// Only output comma with space for values that are NOT the last value | |
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
Value Wrapper and Full Wrapper must be disabled for this to work, which is the case by default, so unless you specifically enabled them, you do not need to worry about it.
Other examples:
https://gist.github.com/tripflex/7fa23b6250d74609b8a8
https://gist.github.com/tripflex/cf5e51a0e9342535038926afce9498b5