Trying to fetch products ID and the products variable ID in Mysql.
My category is 7006.
This query gives me only the general product, and not the product variables values.
SELECT post.ID, post.post_title, metavalue1.meta_value AS MetaValue1, metavalue2.meta_value AS MetaValue2
FROM wp_posts post
LEFT JOIN wp_postmeta metavalue1 ON post.ID = metavalue1.post_id
AND '_enable_colorlab' = metavalue1.meta_key
LEFT JOIN wp_postmeta metavalue2 ON post.ID = metavalue2.post_id
AND '_wcpa_product_meta' = metavalue2.meta_key
LEFT JOIN wp_term_relationships rs ON rs.object_id = post.ID
WHERE rs.term_taxonomy_id ='7006';
This query gives me all variables ID i need
SELECT post.ID, post.post_title FROM wp_posts post
INNER JOIN wp_postmeta pa ON pa.post_id = post.ID
INNER JOIN wp_term_relationships rs ON rs.object_id = post.ID
WHERE rs.term_taxonomy_id ='7006';
How can i get first query to include all product and variables values and not the general product value?
2
Answers
You can try something like this:
In PHP you can explode concatenated string of values
IT will return variation products with variant id.