I created a plugin with a new table (wp_soundcloud) and I need to retrieve the data from that new table along with the post data.
Here is my query:
$querystr = "
SELECT $wpdb->posts.*,
FROM $wpdb->posts
LEFT JOIN $wpdb->soundcloud ON($wpdb->posts.ID = $wpdb->soundcloud.idpost)
WHERE $wpdb->posts.post_type = 'soundcloud'
AND $wpdb->posts.post_name = '$name'
";
$pageposts = $wpdb->get_results($querystr, OBJECT);
…and here is debug:
["last_query"]=>
string(176) "
SELECT wp_posts.*, .*
FROM wp_posts
LEFT JOIN ON(wp_posts.ID = .idpost)
WHERE wp_posts.post_type = 'soundcloud'
AND wp_posts.post_name = 'test-demo'
"
…and the error:
["last_error"]=>
string(226) "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FROM wp_posts
LEFT JOIN ON(wp_posts.ID = .idpost)
WHERE wp_posts.post_' at line 2"
The problem is the LEFT JOIN ON(wp_posts.ID = .idpost). But why did the query not JOIN the table?