admin管理员组

文章数量:1328035

I'm trying to get all the products that exists in database, but my code return empty objects. just for the sake of testing, first I'm trying to get only 10 products, here is my code

add_action('rest_api_init', 'getProducts');
function getProducts()
{
    register_rest_route('products/v1/', 'allproducts', array(
        'methods' => WP_REST_Server::READABLE,
        'callback' => 'allProducts',
    ));
}
function allProducts()
{
    $products = wc_get_products(array(
        'limit' => 10
    ));
    return $products;
}

本文标签: wp querywcgetproducts() return empty object