functions.php
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
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;
}
functions.php
<?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;
}
No comments yet.