Site logo

Archived topic

display meta for custom taxonomies

8 replies · Started by dale on May 7, 2018

Viewing posts 1–9 of 9

Howdy!

I am using the Custom Post Type UI plugin to create custom taxonomies for several websites. For the website linked here, the custom taxonomy types are Format, Genre, and Pay Rate, and each has their own set of taxonomies that I add to organize the posts. For example, Genre has "adventure", "sci fi", "romance", and so forth as possible taxonomies.

How can I display the custom taxonomy type and "tags" in post meta? I definitely would like to display it on individual posts in the meta section (along with tags and categories). It's less important to display them with post experts on the front page of the blog, but it would be nice to have that option too.

(And if you recommend a different plugin or code for custom taxonomies, let me know. I've only installed Custom Post Type UI on one site so far.)

Thanks!

Hi there,

So right now you're displaying categories and tags, and you want to include your custom taxonomy terms after the tags?

Let me know :)

No, I want to display them as "format: blah blah blah" "genre: yadda yadda" and so forth. Their own thing, like tags and categories meta are their own things.

Did that make sense?

Somewhat complex, but you could try something like this:

add_action( 'generate_after_entry_content', 'tu_add_custom_tax_terms', 50 );
function tu_add_custom_tax_terms() {
	$taxonomies = array( 
	  'post_tag' => 'Tags', 
	  'category' => 'Categories',
	);
  
  	echo '<footer class="entry-meta">';

  		foreach ( $taxonomies as $id => $name ) {
                        $term_list = get_the_term_list( get_the_ID(), $id, '', ', ' );
                        if ( $term_list ) {
	  		    echo '<div class="taxonomy">';
				echo $name . ': ' . get_the_term_list( get_the_ID(), $id, '', ', ' );
	  		    echo '</div>';
                        }
		}
  
  	echo '</footer>';
}

Thanks! For some reason, commas aren't appearing between each term. Do I need to add something else? This is the code I used:

add_action( 'generate_after_entry_content', 'tu_add_custom_tax_terms', 50 );
function tu_add_custom_tax_terms() {
	$taxonomies = array( 
	  'post_tag' => 'Tags', 
	  'category' => 'Categories',
	  'genres' => 'Genres',
	  	  'format' => 'Format',
	  	  'payment' => 'Payment',

	);
  
  	echo '<footer class="entry-meta">';

  		foreach ( $taxonomies as $id => $name ) {
	  		echo '<div class="taxonomy">';
				echo $name . ': ' . get_the_term_list( get_the_ID(), $id, '', '', '' );
	  		echo '</div>';
		}
  
  	echo '</footer>';
}

You can see an example of how it generated at the bottom of https://www.dalecameronlowry.com/submission-call-cosmic-roots-eldritch-shores-june/

Also, to remove/hide the taxonomy (for example tags) when no terms are added, would I add an if/then line under

echo $name . ': ' . get_the_term_list( get_the_ID(), $id, '', '', '' );

Thanks so much!

P.S. to add this via GP hooks, would I do it as:

<?php {
?>
add_action('tu_add_custom_tax_terms', 50 );
function tu_add_custom_tax_terms() {
$taxonomies = array(
'post_tag' => 'Tags',
'category' => 'Categories',
'genres' => 'Genres',
'format' => 'Format',
'payment' => 'Payment',

);

echo '<footer class="entry-meta">';

foreach ( $taxonomies as $id => $name ) {
echo '

';
echo $name . ': ' . get_the_term_list( get_the_ID(), $id, '', '', '' );
echo '

';
}

echo '</footer>';
}
<?php }
?>

Thank you! It works great when added to functions php.

For some reason I couldn't get it to work in GP hooks. I used:

<?php
if ( in_category( 'for-writers' ) && is_single() )
{ ?>

add_action( 'tu_add_custom_tax_terms', 50 );
function tu_add_custom_tax_terms() {
	$taxonomies = array( 
	  'post_tag' => 'Tags', 
	  'category' => 'Categories',
	);
  
  	echo '<footer class="entry-meta">';

  		foreach ( $taxonomies as $id => $name ) {
                        $term_list = get_the_term_list( get_the_ID(), $id, '', ', ' );
                        if ( $term_list ) {
	  		    echo '<div class="taxonomy">';
				echo $name . ': ' . get_the_term_list( get_the_ID(), $id, '', ', ' );
	  		    echo '</div>';
                        }
		}
  
  	echo '</footer>';
}
<?php }
?>

Did I make an error?

It would need to look like this in GP Hooks:

<?php if ( in_category( 'for-writers' ) && is_single() ) : ?>
    $taxonomies = array( 
        'post_tag' => 'Tags', 
        'category' => 'Categories',
    );

    echo '<footer class="entry-meta">';

        foreach ( $taxonomies as $id => $name ) {
            $term_list = get_the_term_list( get_the_ID(), $id, '', ', ' );
            if ( $term_list ) {
                echo '<div class="taxonomy">';
                    echo $name . ': ' . get_the_term_list( get_the_ID(), $id, '', ', ' );
                echo '</div>';
            }
        }
  
    echo '</footer>';
<?php endif; ?>
This archived topic is closed to new replies.