T
T
takoinickname2020-06-06 12:01:23
WooCommerce
takoinickname, 2020-06-06 12:01:23

Why are the products not found?

<?php
        $args = array(
            'post_type' => 'product',
            'posts_per_page' => 16,
      'category_name' => 'lestnitsy',
            );
        $loop = new WP_Query($args);
        if ( $loop->have_posts() ) {
            while ( $loop->have_posts() ) : $loop->the_post();
                echo ' 1 ';
            endwhile;
        } else {
            echo __( 'No products found' );
        }
        wp_reset_postdata();
    ?>


This is how the products are not found, it gives out No products found, I tried to use cat instead of category_name, it still does not appear, if you remove the category_name, then all products are displayed, posts_per_page - it works.
lestnitsy - this is the slug specified in the wokomerts headings, cat took from the tag_id in the url when you enter the wokomerts heading.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
takoinickname, 2020-06-06
@takoinickname

that's how it works

$args = array(
            'post_type' => 'product',
            'posts_per_page' => 16,
      'tax_query' => array(
            array(
                'taxonomy' => 'product_cat',
                'field' => 'id',
                'terms' => 299
            ))
            );

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question