0

I am looking for some suggestion on how to run a query on wp-term with multiple "same column name as different attribute name" bottom line I am trying to query woocommerce products + all their attributes in following format:

<thead> <th>name</th> | <th>color</th> | <th>clarity</th> | <th>shape</th> | <th>size</th> 

<tr><td>product 1</td>|<td>H</td>|<td>good</td>|<td>heart</td>| <td>big</td></tr>

with the following code I am only getting one of the attribute but I am not sure how to add the second and third and rest of attribute to this query.

$var = "SELECT p.`ID` AS 'Product ID',
       p.`post_title` AS 'Product Name',
       t.`name` AS 'carat'
       FROM `wp_posts` AS p
       INNER JOIN `wp_term_relationships` AS tr ON p.`ID` = tr.`object_id`
       INNER JOIN `wp_term_taxonomy` AS tt ON tr.`term_taxonomy_id` = tt.`term_id`
       AND tt.`taxonomy` LIKE 'pa_carat%' 
       INNER JOIN `wp_terms` AS t ON tr.`term_taxonomy_id` = t.`term_id`
       WHERE p.`post_type` = 'product'
       AND p.`post_status` = 'publish'"
  • Is it for simple products, variable products, product variations? Try to clarify your question as product attribute can be also set for variations or not. – LoicTheAztec Sep 7 at 9:33
  • Thanks. This is for a simple product. The attributes are not set for variation. – Ali RJ Sep 7 at 20:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.