How to query posts from categories with specific tags? For Example if I visit "localhost/tag/tutorial" the archive page would show all post from all category with tutorial tag.
But the view would be seperated by category. For example:
Category 1
- Category 1 Post 1 With tutorial tag
- Category 1 Post 2 with tutorial tag
Category 2
- Category 2 Post 2 With tutorial tag
- Category 2 Post 10 With tutorial tag
NB: The posts show in each categories with same tags.
I have a code that show latest posts in each categories
<?php
$categories = get_categories();
foreach($categories as $category) { ?>
<div class="CategoryPost">
<h2><?php echo $category->name; ?></h2>
<ul>
<?php
$post_args = array(
'category' => $category->term_id,
'numberposts' => 9999,
'orderby'=> 'post_date',
'order' => 'ASC',
'post_type' => 'post'
);
$posts = get_posts($post_args);
foreach($posts as $post) { ?>
<li id="post-<?php the_ID(); ?>"><span><?php the_time('d M Y') ?></span> <i class="Seperate">»</i> <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
<?php } ?>
</ul>
</div>
<?php }
wp_reset_postdata(); ?>
The code above would show latest posts in each category with this look.
Category 1 Name
- Category 1 Post 1
- Category 1 Post 2
Category 2 Name
- Category 1 Post 1
- Category 1 Post 2
Category 3 Name
- Category 1 Post 1
- Category 1 Post 2
I would like to make a tags archive that work with that template and the posts would be shown in each categories even the posts have the same tags.