How to print term name inside wp post loop

I have 3 different taxonomies in a custom post type. I want to print all posts with term name with them.

for example:

taxonomy 1 =>taxonomy=bankspost_type=creditcards

taxonomy 2 =>taxonomy=joiningfeespost_type=creditcards

taxonomy 3 =>taxonomy=cardtypepost_type=creditcards

So I want to print all the custom posts with the term names I am able to print data by entering single taxonomy but how to print data with all the taxonomy terms

Query

$custom_terms = get_terms('banks');

foreach($custom_terms as $custom_term) {
wp_reset_query();
$args = array('post_type' = 'creditcards',
'tax_query' = array(
       array(
             'taxonomy' = 'banks',
             'field' = 'slug',
             'terms' = $custom_term-slug,
            ),
           ),
);

$loop = new WP_Query($args);
if($loop-have_posts()) {

while($loop-have_posts()) : $loop-the_post();?

div?php echo $custom_term-name;?br?php echo the_title();?/div
 ?php endwhile;
       }
       }
?

End Result that i want in post loop

taxonomy1 term,taxonomy2 term,taxonomy3 term
the title

taxonomy1 term,taxonomy2 term,taxonomy3 term
the title

taxonomy1 term,taxonomy2 term,taxonomy3 term
the title

Topic tax-query terms wp-query custom-taxonomy Wordpress

Category Web


You can access the terms with this function. You can pass the name of the taxonomy as well as the ID to the function. Make sure to grab the ID correctly inside the loop - get_the_ID() should work. After that it's a matter of joining the results with comma separation. With array_merge you can add also additional arrays that you need.

  $x_terms = get_the_terms( get_the_ID(), 'any-taxonomy-slug');
  $y_terms = get_the_terms( get_the_ID(), 'another-taxonomy-slug');

  $terms = array_merge($x_terms, $y_terms);

  foreach($terms as $term):
     $term_names[] = $term->name;
  endforeach;

  $names = join( ", ", $term_names );

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.