I have a WP_Query that outputs posts that belong to a custom post type taxonomy.
<p> <?php echo "Productions: "; $args = array('post_type' => 'productions', 'tax_query' => array ( array ( 'taxonomy' => 'directors', 'field' => 'id', 'terms' => get_the_ID() ) )); $query = new WP_Query( $args ); // The Query $the_query = new WP_Query( $args ); // The Loop while ( $the_query->have_posts() ) : $the_query->the_post(); ?> <a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a>, <?php endwhile; ?> </p>
This all works fine, but there are two things that I don't know how to do:
-i want to separate the output with commas -> Productions: Rambo, Terminator 2, Highlander
-If there are no posts, then it should be empty. At the moment, when there are no posts, it shows Productions: