I cannot display custom posts in custom taxonomy

I have a problem with display posts in custom taxonomy. I created custom post type m_product and custom taxonomy for this post type m_product_category. I created file in main theme folder named taxonomy-m_product_category.php and maked html for it:

protectFile();

get_header();
$paged = ( get_query_var( ‘paged’ ) ) ? get_query_var( ‘paged’ ) : 1;
print_r($wp_query);
?>
<div class=”top-bg” style=”background-image: url(<?php echo THEME_IMAGES_URI; ?>/ronney-produkty-akcesoria-salon-fryzjerski-str-kategorie-produktow-tlo-01.jpg)”></div>
<?php
echo do_shortcode(‘[meetProducts]’);
if (have_posts()) {
?>
<div class=”container py-5″>
<div class=”row” id=”products-list”>
<?php
while (have_posts()) {
the_post();
$subtitle = get_field(‘m_product_subtitle’);
?>
<div class=”col-12 col-md-3 mb-3″>
<a href=”<?php echo the_permalink(); ?>” class=”product-box d-block” rel=”noopener”>
<?php
if (has_post_thumbnail()) {
the_post_thumbnail(‘thumbnail’, [‘class’ => ‘d-block mx-auto img-fluid’]);
}
?>

<div class=”text-center mt-3 product-box-title”>
<?php
the_title();

if ($subtitle) {
?>
<div class=”product-box-subtitle”>
<?php echo sanitize_text_field($subtitle); ?>
</div>
<?php
}
?>

</div>
</a>
</div>
<?php
}
?>
</div>

<?php
if ($paged < $wp_query->max_num_pages) {
?>
<div class=”text-center mt-4″>
<button type=”button” class=”load-more-products btn btn-secondary btn-sm” data-next-page=”<?php echo esc_attr($paged + 1); ?>” data-max-page=”<?php echo esc_attr($wp_query->max_num_pages); ?>”>Wczytaj więcej</button>
</div>
<?php
}
?>
</div>
<?php
wp_reset_postdata();
} else {
echo ‘test’;
}
echo do_shortcode(‘[meetProducts]’);
get_footer();

But when i go to the custom taxonomy page, can’t display posts in while loop, i mean is nothing to see. I didn’t make any functions which should change some queries for taxonomies. Archive working properly, i don’t have set public to false or something for register taxonomy, I will show you register taxonomy code:

// Protect file
protectFile();

function custom_taxonomy_m_product_category() {
register_taxonomy(‘m_product_category’, [‘m_product’], [
‘hierarchical’ => true,
‘labels’ => $labels,
‘show_ui’ => true,
‘show_admin_column’ => true,
‘exclude_from_search’ => false,
‘query_var’ => true,
‘public’ => true,
‘rewrite’ => [
‘slug’ => ‘cat-slug’
],
]);
}

add_action(‘init’, ‘custom_taxonomy_m_product_category’, 0);

I rewrited link in settings but this doesn’t help. I don’t have idea why this isn’t working, could someone give me advice? Thanks!

Read more here:: I cannot display custom posts in custom taxonomy

Leave a Reply

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