Created
November 27, 2013 14:25
-
-
Save calliaweb/7676494 to your computer and use it in GitHub Desktop.
Modify Post Meta to add custom taxonomies
Author Jo Waltham jo@calliaweb.co.uk
Add function to your functions.php
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
/** Modify Post Meta to add custom taxs | |
* Author Jo Waltham jo@calliaweb.co.uk | |
* Add function to your functions.php | |
*/ | |
add_filter( 'genesis_post_meta', 'jmw_post_meta_filter' ); | |
function jmw_post_meta_filter($post_meta) { | |
if ( !is_single() ) // Only runs on single posts - remove if you want the output on archive pages | |
return; | |
$post_meta = ''; // Resets the post meta to blank string | |
// Get list of taxonomies | |
$args = array( | |
'public' => true, | |
'_builtin' => false //Change to true if you want to include Categories and Tags | |
); | |
$taxonomies = get_taxonomies( $args, 'objects'); | |
if( !$taxonomies ) // If this post doesn't have custom taxonomies return | |
return; | |
// For each taxonomy add the term links | |
foreach ($taxonomies as $taxonomy ) { | |
unset( $items ); // clear the array | |
$term_list = wp_get_post_terms( get_the_ID(), $taxonomy->name, array("fields" => "all")); // Get list of all the terms this post has in this taxonomy | |
foreach ( $term_list as $single_term ) { | |
$term_link = get_term_link( $single_term->name, $taxonomy->name ); // Get the term link | |
if ( !is_wp_error( $term_link ) ) $items[] = '<a href="' . esc_url( $term_link ) .'">' . $single_term->name . '</a>'; // Add term to the string | |
} | |
if( $items ) { | |
$post_meta = $post_meta . $taxonomy->labels->name . ': ' . implode( ', ', $items ) . "<br />"; // Create the new post meta string | |
} | |
} | |
return $post_meta; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment