How to query WordPress database with Left Join

admin

Administrator
Staff member
So I am trying to pull information about business listings from a wordpress database. The information is stored in the wp_posts table and the wp_postmeta table where all of the additional business information is listed.

The wp_postmeta table saves data like this: each piece of data has it's own row, the information is not stored as a serialized array all in one row.

Here is my database query so far:

Code:
$wpdb->get_results(
    " SELECT * FROM " . $wpdb->posts    . 
    " LEFT JOIN "     . $wpdb->postmeta . 
    " ON "            . $wpdb->posts    . ".ID = " . $wpdb->postmeta . ".POST_ID" . 
    " WHERE "         . $wpdb->posts    . ".POST_TYPE = 'lv_listing' " .
    " AND "           . $wpdb->posts    . ".POST_STATUS = 'publish' " . 
    " GROUP BY "      . $wpdb->posts    . ".ID");

Currently, each set of results gives me only one row from the wp_postmeta table, where I am expecting like 20 rows that should match the ID I am grouping by.
What am I doing wrong?