So I have a custom post type called Video
and a taxonomy called category
that I use to group videos togheter, so I want to list them like this:
Taxonomy NAME 1
VIDEO 1
VODEO 2
Taxonomy NAME 2
Video 1
Video 2
So I tried something but it doesn't work, the problem is that for each video I also display the taxonomy name like this:
Taxonomy Name 1
Video 1
Taxonomy Name 1
Video 2
So this is not what I want, mabe you guys can figure it out, what I do wrong:
<?php get_header();?>
<?php
$args = array( 'post_type' => 'Video');
$loop = new WP_Query( $args );
?>
<?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
<?php $fg = get_the_terms(get_the_ID(),'category'); ?>
<?php foreach($fg as $term): ?>
<h2><?php echo $term->name; ?></h2>
<?php wp_reset_postdata(); ?>
<?php
$posts = new WP_Query(array('post_type' => 'Video', 'category' => $term->name) );
while ( $posts->have_posts() ) : $posts->the_post();
the_post_thumbnail();
?>
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
<?php
endwhile;
?>
<?php endforeach; ?>
<?php endwhile; ?>
<?php get_footer(); ?>
If someone can help please do it :( I can't get this