Im new to mysql queries and im having trouble obtaining the data structure I want. Im hoping one of you guys can help.
I have the following query:
SELECT *
FROM wp_postmeta
WHERE post_id IN (SELECT id from wp_posts WHERE post_type = 'product')
Which simply grabs all the data from Table 2 that has the same id as the product in Table 1. The problem is that the results return as:
{meta_id: "37230", post_id: "2549", meta_key: "total_sales", meta_value: "0"}
{meta_id: "37231", post_id: "2549", meta_key: "_virtual", meta_value: "no"}
{meta_id: "37232", post_id: "2549", meta_key: "_tax_status", meta_value: "taxable"}
{meta_id: "37233", post_id: "2549", meta_key: "_visibility", meta_value: "visible"}
{meta_id: "37234", post_id: "2549", meta_key: "_featured", meta_value: "no"}
{meta_id: "37235", post_id: "2549", meta_key: "_weight", meta_value: "0.50"}
{meta_id: "37236", post_id: "2549", meta_key: "_sku", meta_value: "HCS-DGMP"}
{meta_id: "37237", post_id: "2549", meta_key: "_product_attributes", meta_value: "a:0:{}"}
{meta_id: "37238", post_id: "2549", meta_key: "_regular_price", meta_value: "18.99"}
{meta_id: "37239", post_id: "2549", meta_key: "_sale_price", meta_value: ""}
As you can see, they all have the same post ID, but are returned in seperate objects. How can I modify my query above so that all of that returns in one object? I'll also be removing the meta_id
as it is useless.