1
votes

I am trying to get current post custom taxonomy link and name separately to put some schema data and my code is:

<?php $args = array('taxonomy' => 'developer'); ?>
<?php $tax_menu_items = get_categories( $args );
foreach ( $tax_menu_items as $tax_menu_item ):?>
<meta itemprop="url" content="<?php echo get_term_link($tax_menu_item,$tax_menu_item->taxonomy); ?>"></meta>
<a href="<?php echo get_term_link($tax_menu_item,$tax_menu_item->taxonomy); ?>">
<span itemprop="name"><?php echo $tax_menu_item->name; ?></span></a>
<?php endforeach; ?>
</div>`

The problem is that the above code is displaying all the "developer" which have at least one post and not the current post taxonomy.

How can I fix this!

1
at last I have solved this myself !Tuhin A.

1 Answers

1
votes
<meta itemprop="url" content="<?php $terms = wp_get_post_terms( $post->ID, 'developer'); foreach($terms as $term) {
            echo "" . get_term_link($term) . ""; } ?>"></meta>
        <?php $terms = wp_get_post_terms( $post->ID, 'developer'); foreach($terms as $term) {
        echo '<a href="' . get_term_link($term) . '"><span itemprop="name">' . $term->name . '</span></a>'; } 
        ?>