Pages of my taxonomy terms are showing all posts

I have two main taxonomies:
1. Libros
2. Asuntos

and multiple taxonomy terms:
1. Al Bujari
2. Muslim
3. La Paciencia
4. La Fe
5. La Caridad
and many other taxonomy terms using the custom post type: hadices.

The case is that when I click on the slug related to any of the taxonomy terms above, it displays all the posts not just the posts related to the taxonomy term I clicked. I am working on the taxonomy.php file. Here is the code I have on the taxonomy.php:

<?php $taxes = array( ‘libro_de_hadiz’ , ‘asunto’);
$terms = get_terms( $taxes );
echo $terms;
$paged = ( get_query_var( ‘paged’ ) ) ? absint ( get_query_var( ‘paged’ ) ) : 1;
$args = array( ‘post_type’ => ‘hadices’,
‘posts_per_page’ => 6,
‘paged’ => $paged,
));
$loop = new WP_Query( $args );

if ( $loop->have_posts() ) : ?>
<header class=”page-header”>
<?php
the_archive_title( ‘<h1 class=”page-title”>’, ‘</h1>’ );
the_archive_description( ‘<div class=”taxonomy-description”>’, ‘</div>’ );
?>
</header><!– .page-header –>
<?php endif; ?>

<div id=”primary” class=”content-area”>
<main id=”main” class=”site-main” role=”main”>

<?php
if ( $loop->have_posts() ) : ?>
<?php
/* Start the Loop */
while ( $loop->have_posts() ) : $loop->the_post();

/*
* Include the Post-Format-specific template for the content.
* If you want to override this in a child theme, then include a file
* called content-___.php (where ___ is the Post Format name) and that will be used instead.
*/
get_template_part( ‘template-parts/post/content’, get_post_format() );

$loop->the_posts_pagination( array(
‘prev_text’ => twentyseventeen_get_svg( array( ‘icon’ => ‘arrow-left’ ) ) . ‘<span class=”screen-reader-text”>’ .$loop-> __( ‘Previous page’, ‘twentyseventeen’ ) . ‘</span>’,
‘next_text’ => ‘<span class=”screen-reader-text”>’ . $loop->__( ‘Next page’, ‘twentyseventeen’ ) . ‘</span>’ . twentyseventeen_get_svg( array( ‘icon’ => ‘arrow-right’ ) ),
‘before_page_number’ => ‘<span class=”meta-nav screen-reader-text”>’ . $loop->__( ‘Page’, ‘twentyseventeen’ ) . ‘ </span>’,
) );

endwhile;
$big = 999999999; // need an unlikely integer
echo paginate_links( array(
‘base’ => str_replace( $big, ‘%#%’, get_pagenum_link( $big ) ),
‘format’ => ‘/paged/%#%’,
‘current’ => max( 1, get_query_var(‘paged’) ),
‘total’ => $loop->max_num_pages
) );
else :

get_template_part( ‘template-parts/post/content’, ‘none’ );

endif; wp_reset_postdata(); ?>

</main><!– #main –>
</div><!– #primary –>
<?php get_sidebar(); ?>

I have seen the answers to the post in this link:
Archive template for taxonomy terms

However the answers were just saying to add a taxonomy-term.php for each term, which will be very tedious in my case as I would need tens of files with similar code just changing the term slug in the tax_query. Is there a way to add a dynamic variable for the terms in tax_query to show only the posts related to the term or any other solution if any?

Thanks in advance

Read more here:: Pages of my taxonomy terms are showing all posts

Leave a Reply

Your email address will not be published. Required fields are marked *