Answers for "wordpress php get all product from categories"

0

woocommerce get product categories

$terms = get_the_terms( $product_id, 'product_cat' );
foreach ($terms as $term) {
    $product_cat_id[] = $term->term_id;
}
Posted by: Guest on July-23-2021
0

wp_query product category

$args = array(
    'post_type'             => 'product',
    'post_status'           => 'publish',
    'ignore_sticky_posts'   => 1,
    'posts_per_page'        => '12',
    'tax_query'             => array(
        array(
            'taxonomy'      => 'product_cat',
            'field' => 'term_id', //This is optional, as it defaults to 'term_id'
            'terms'         => 26,
            'operator'      => 'IN' // Possible values are 'IN', 'NOT IN', 'AND'.
        ),
        array(
            'taxonomy'      => 'product_visibility',
            'field'         => 'slug',
            'terms'         => 'exclude-from-catalog', // Possibly 'exclude-from-search' too
            'operator'      => 'NOT IN'
        )
    )
);
$products = new WP_Query($args);
var_dump($products);
Posted by: Guest on April-20-2021

Code answers related to "wordpress php get all product from categories"

Browse Popular Code Answers by Language