Skip to content

Instantly share code, notes, and snippets.

@tripflex
Created December 13, 2017 17:43
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/40b88368fea57507eeced7ee25e41102 to your computer and use it in GitHub Desktop.
Save tripflex/40b88368fea57507eeced7ee25e41102 to your computer and use it in GitHub Desktop.
Output custom term meta for taxonomy field when using WP Job Manager Field Editor
<?php
// ^ this should only exist once at the top of child theme's functions.php file
// ADD THIS CODE TO YOUR CHILD THEME FUNCTIONS.PHP FILE OR USING THE CODE SNIPPETS PLUGIN
// MAKE SURE YOU UPDATE THE FIELDS BELOW, SPECICIALLY 'some_taxonomy_metakey' TO MATCH THE META KEY CONFIGURED IN FIELD EDITOR
// AND 'some_term_meta_key' TO MATCH THE META KEY SETUP IN PODS OR WHEN CREATING THE TAXONOMY META FIELD
add_filter( 'field_editor_get_custom_field_listing_meta', 'smyles_custom_taxonomy_meta_output', 10, 4 );
function smyles_custom_taxonomy_meta_output( $values, $meta_key, $listing_id, $args ){
// We only want to process a specific meta key, taxonomy values should be an array, and taxonomy arg should be set
if( $meta_key !== 'some_taxonomy_metakey' || ! is_array( $values ) || ! isset( $args['taxonomy'] ) || empty( $args['taxonomy'] ) ){
return $values;
}
// Set this to the meta key set in PODS or whatever used to create custom meta in taxonomy
$term_meta_key = 'some_term_meta_key';
$term_metas = array();
foreach( $values as $term_name ){
$term = get_term_by( 'name', $term_name, $args['taxonomy'] );
if( $term ){
$meta_value = get_term_meta( $term->term_id, $term_meta_key, true );
if( $meta_value ){
$term_metas[] = $meta_value;
}
}
}
if( ! empty( $term_metas ) ){
return $term_metas;
}
return $values;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment