How to display hiiden or exclude-from-catalog product via query?
-
Hello, I am trying to display products that are on sale, including products that are hidden for the catalog and are also on sale. unfortunately, no products are displayed even though I have several products that are hidden for the catalog and have a discount
Thank you for help
<?php
// Nastavení po?tu sloupc? pro WooCommerce
wc_set_loop_prop('columns', 4);
// Získání aktuální stránky
$paged = get_query_var('paged') ? get_query_var('paged') : 1;
// Dotaz pro produkty ve slevě s viditelností 'hidden'
$args = array(
'post_type' => 'product',
'posts_per_page' => 30, // Po?et produkt? na stránku
'orderby' => 'meta_value_num',
'order' => 'desc',
'meta_key' => 'total_sales',
'paged' => $paged, // Nastavení aktuální stránky
'meta_query' => array(
array(
'key' => '_sale_price',
'value' => 0,
'compare' => '>',
'type' => 'NUMERIC',
),
),
'tax_query' => array(
array(
'taxonomy' => 'product_visibility',
'field' => 'name',
'terms' => array('exclude-from-catalog', 'exclude-from-search'),
'operator' => 'IN', // Zahrnout produkty, které jsou skryté z katalogu nebo vyhledávání
),
),
);
var_dump($args);
// Vytvo?ení nového WP_Query objektu
$products_query = new WP_Query($args);
if ($products_query->have_posts()) :
while ($products_query->have_posts()) : $products_query->the_post();
wc_get_template_part('content', 'product');
endwhile;
// Zobrazení stránkování
echo paginate_links(array(
'total' => $products_query->max_num_pages,
'current' => $paged,
'format' => '?paged=%#%', // Zajistit správny formát URL pro stránkování
'prev_text' => __('? P?edchozí'),
'next_text' => __('Dal?í ?'),
));
else :
// Zpráva, pokud nejsou ?ádné produkty k dispozici
echo '?ádné produkty nenalezeny.';
endif;
// Obnova p?vodních dat query
wp_reset_postdata();
?>
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘How to display hiiden or exclude-from-catalog product via query?’ is closed to new replies.