Answer the question
In order to leave comments, you need to log in
Is it possible to include content-product in the taxonomy-product_cat file?
Here is an example:
<?php
$args = array(
'post_type' => 'product',
'tax_query' => array(
array(
'taxonomy' => 'product_cat',
'field' => 'name',
'terms' => 'featured',
),
),
'posts_per_page' => -1,
);
global $wp_query;
$wp_query = new WP_Query( $args );
if ( $wp_query->have_posts() ) :
?>
<?php while( $wp_query->have_posts() ) : $wp_query->the_post(); ?>
<?php wc_get_template_part( 'content', 'content-product' ); ?>
<?php endwhile; ?>
<?php else : ?>
<div>Товаров не найдено</div>
<?php endif; ?>
Answer the question
In order to leave comments, you need to log in
It is possible, but why not, but 2 clarifications
1. 'field' => 'name', will search for the title of the category and not the slug,
2. wc_get_template_part( 'content', 'content-product' ); - will look for the template content-content-product.php and not content-product.php
well, the nuances for ul
should look something like this
<?php
/**
* Template Name: Бла бла бла
*/
get_header();
$args = [
'post_type' => 'product',
'tax_query' => [
[
'taxonomy' => 'product_cat',
'field' => 'name',
'terms' => 'Tem Name',
],
],
'posts_per_page' => - 1,
];
global $wp_query;
$wp_query = new WP_Query( $args );
if ( $wp_query->have_posts() ) :
woocommerce_product_loop_start();
?>
<?php while ( $wp_query->have_posts() ) : $wp_query->the_post();
?>
<?php wc_get_template_part( 'content', 'product' ); ?>
<?php endwhile;
woocommerce_product_loop_end();
?>
<?php else : ?>
<div>Товаров не найдено</div>
<?php endif;
get_footer();
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question