George Pennet George Pennet - 7 days ago 5
PHP Question

Displays the total number of products

What code use to display the total number of products? I want to make a section with icons on the main page of my store and it would be great to include something like that.

Best Regards

Answer

In case if you wants to show total number of published products in your store, use the following code:

$args = array( 'post_type' => 'product', 'post_status' => 'publish', 
'posts_per_page' => -1 );
$products = new WP_Query( $args );
echo $products->found_posts;

It sill return total number of published products in your store.

Comments