I am trying to get the woocommerce products by category.. When I query using the wpdb it gets the product correctly which exists in the backend products list. But when I query using the query_posts it gets another set of products that is not listed in the backend.
Why this discrepancy?
global $post, $wpdb;
$query = "SELECT $wpdb->posts.* FROM $wpdb->posts
LEFT JOIN $wpdb->term_relationships ON
($wpdb->posts.ID = $wpdb->term_relationships.object_id)
LEFT JOIN $wpdb->term_taxonomy ON
($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id)
WHERE $wpdb->posts.post_status = 'publish'
AND $wpdb->term_taxonomy.taxonomy = 'product_cat'
AND $wpdb->term_taxonomy.term_id = 1
$childcond
ORDER BY post_date DESC";
if ($wpdb->num_rows > 0) {
foreach ($postresults as $post) {
//process product item
}
}
using query_post
query_posts('cat=1&showposts=-1');