1

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

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

2 Answers 2

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>
0

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>
2
  • After Try this one, It's return Notice: Array to string conversion in C:\Program Files (x86)\Ampps\www\songs\wp-includes\formatting.php on line 1031
    – jone hans
    Commented Apr 5, 2017 at 21:21
  • please do the minimum of debugging before to ask a question. that means looking at every variable to see if the contains the expected values and writing these values in the question. look also this page : stackoverflow.com/questions/12769982/…
    – mmm
    Commented Apr 5, 2017 at 21:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.