$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>plugin development - woocommerce wc_get_product is not fetching all the product of particular category|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

plugin development - woocommerce wc_get_product is not fetching all the product of particular category

matteradmin10PV0评论

I have created dummy product data with fakerpress and many products were created with "future" status, so I updated the post status to "publish". I wanted to retrieve all the product of selected category. Code for it is :

    $args = array(
        'limit'    => -1,
        'status'   => 'publish',
        'category' => array('clothing'),
    );

    $products = wc_get_product($args);
    echo "<pre>";
    print_r(count($products));
    echo "</pre>";
    exit();

It is returning only 8 products but i have 128 product in this category. I also created product with the woo-commerce sample csv file, on doing so, I am getting the product count exactly as it should be. Can anyone please provide me the hint for what needs to be done ? Any kinds of help are appreciated. Thanks.

EDIT: What I found is,some products are already in publish status and they are not fetched, but if i edit that product and simply update the product without changing any data, it is fetched. What could be the reason of this. Any ideas ?

WP_Query for fetching posts :

    $categories = array(1,2,3); // IDs of categories
    $args = array(
        'post_type'             => 'product',
        'post_status'           => 'publish',
        'ignore_sticky_posts'   => 1,
        'posts_per_page'        => -1,

        'tax_query'             => array(
            array(
                'taxonomy'      => 'product_cat',
                'field' => 'term_id', //This is optional, as it defaults to 'term_id'
                'terms'         => implode(',',$categories),
                'operator'      => 'IN' // Possible values are 'IN', 'NOT IN', 'AND'.
            )
        )
    );
   $postProducts = new WP_Query($args);

This returns the post data as required but cannot retrieve meta_keys and values associated with product.

Post a comment

comment list (0)

  1. No comments so far