O
O
Oblom4ik2017-10-10 17:24:47
Taxonomy
Oblom4ik, 2017-10-10 17:24:47

How to display a category in a carousel?

Good day.
I decided to display a carousel with "products" on the WP site.
The products are created through ACF, and a taxonomy has also been created for them.
This assumes that I create a taxonomy called "bestseller" and try to display it with the code:
<?php if ( have_posts()): query_posts('category__in=25'); while ( have_posts() ) : the_post(); ?>
blah blah blah
<?php endwhile; endif ?>
But it doesn't work - the carousel is empty. There was another option to replace 'category__in=25' with 'cat=25' - similarly.
Why did I even decide that my code is working?
If you do not set a restriction on categories, then on the category page this code duplicates the one displayed there and the carousel is filled with products.
The only question is how to make a conclusion in the carousel of exactly the category / heading I need?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
4
4mobile, 2017-10-10
@Oblom4ik

query_posts should not be used.
category__in only fires for categories.
You have your own taxonomy, so

$args = array(
  'post_type' => 'product',
  'custom_tax'    => 'hit'
);
$query = new WP_Query( $args );
while ( $query->have_posts() ) {
  $query->the_post();
  the_title(); // выведем заголовок поста
}
wp_reset_postdata();

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question