Skip to content

Instantly share code, notes, and snippets.

@tripflex
Created December 11, 2016 03:03
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/8226e1b4b2a07cf373215fe432140d8c to your computer and use it in GitHub Desktop.
Save tripflex/8226e1b4b2a07cf373215fe432140d8c to your computer and use it in GitHub Desktop.
How to output value/separator for multiple (inc taxonomy) fields when not using full or value wrapper in WP Job Manager Field Editor
<?php
/**
* If you are using shortcode, or auto output and do not have the full AND value wrapper being output (output as value only),
* you can use this code below to use something different than the regular <br /> that is output by default
*/
add_filter('field_editor_output_no_wrap_after', 'smyles_custom_no_wrap_after', 10, 6);
function smyles_custom_no_wrap_after( $output, $meta_key, $listing_id, $field_values, $args, $single_value ){
// Array indexes start at 0, to get the last we need to minus 1 from total
$last_value_index = ( count( $field_values ) - 1 );
// Get where our current value output is at
$current_index = array_search( $single_value, $field_values);
// Return empty string if this is the last value
if( $last_value_index === $current_index ){
return '';
}
// Return ", and " for second to last value
if( $current_index === ( $last_value_index -1 ) ){
return ', and ';
}
// Return comma instead of <br /> for "job_region" meta key
if( $meta_key === 'job_region' ){
return ', ';
}
// OR check for taxonomy and output comma
if( array_key_exists( 'taxonomy', $args ) && $args['taxonomy'] === 'job_listing_region' ){
return ', ';
}
return $output;
}
@tripflex
Copy link
Author

One thing to mention as well:
You MUST disable FULL and VALUE wrappers for this to work! --- you CAN enable the value wrapper and output though

If you plan on outputting values as CSV you can not use HTML element wrappers as your theme would cause the display to look incorrect.

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