I was recently asked to work on a WooCommerce based site. I was given the simple task of generating a text file that contained all the products within the WooCommerce store. I thought I would just be able to run a simple query on the database and dump the product list. However after a quick look at the database I realized all the products were posts within WordPress. Ok. No problem, I will just run a post query. Well… it took a lot longer than expected to find out what actually needed to be queried to get only the products. Below is a snippet that will allow you to get all the products.
$args = array( 'post_type' => 'product', 'posts_per_page' => -1 );
query_posts( $args );
while ( have_posts() ) : the_post();
print_r($product); //Dump product info
The important part above is the ‘post_type’ => ‘product’ This seems pretty obvious, but if you never needed to use it before it can be hard to figure out. I ended up finding it directly from the WordPress posts database table since I could not find any obvious documentation pointing to this.