admin管理员组

文章数量:1122846

I'm using CMB2 Plugin for creating Custom Meta Box in a Custom Taxonomy. I added fields into that taxonomy. But the problem is when I'm going to display that data in archive template, It seems blank. Here is my Code.

<?php $name = get_post_meta( get_the_ID(), 'game_name', true ); ?>
<h1><?php echo esc_html( $name ); ?></h1>

Now Can you tell me how can I show meta data from a Taxonomy in an Archive page?

Thanks

I'm using CMB2 Plugin for creating Custom Meta Box in a Custom Taxonomy. I added fields into that taxonomy. But the problem is when I'm going to display that data in archive template, It seems blank. Here is my Code.

<?php $name = get_post_meta( get_the_ID(), 'game_name', true ); ?>
<h1><?php echo esc_html( $name ); ?></h1>

Now Can you tell me how can I show meta data from a Taxonomy in an Archive page?

Thanks

Share Improve this question asked Apr 5, 2017 at 20:49 jone hansjone hans 112 bronze badges 3
  • 1 Are you trying to display this term meta-data outside of the Loop while displaying an archive of posts which use the term in question? Or are you trying to display this meta-data within the Loop for each post which uses the term? It would help if you would include which template file you're doing this in, as well as some more code to demonstrate where that snippet is in your template. – bosco Commented Apr 5, 2017 at 21:29
  • You may check this my code.. Custom Taxonomy File: pastebin.com/t9c4zad3 CMB2 Meta Box Filed Code: pastebin.com/xYJvUDUm – jone hans Commented Apr 5, 2017 at 21:35
  • 1 Are you sure you want this meta-data attached to terms? Seems to me singer and composer should be custom taxonomies and release year should be post meta-data - all of these things applied to individual posts of an "album" custom post-type. cover would then simply be the post's featured image. That way you can view an archive of albums, sort and search them by singer and composer (and view singer/composer archives), and use a meta-query to filter them by release year. – bosco Commented Apr 5, 2017 at 22:24
Add a comment  | 

2 Answers 2

Reset to default 1
<?php $terms = get_the_terms( get_the_ID(), 'game_name'); ?>
<h1>
    <?php foreach ($terms as $term) {?>
        <?php echo esc_html($term->name);?>
    <?php }?>
</h1>

try get_the_terms to do that
https://developer.wordpress.org/reference/functions/get_the_terms/

<?php $listeNoms = get_the_terms( get_the_ID(), 'game_name'); ?>
<h1>
    <?php foreach ($listeNoms as $name) {?>
        <?php echo esc_html($name);?>
    <?php }?>
</h1>

本文标签: pluginsHow to Display Taxonomy Custom Meta Box Data in Archive Page