If you have
Unknown column 'wp_postmeta.meta_key'wp_postmeta.meta_key
in 'wherewhere
clause
youYou probably want to join $wpdb->postmeta$wpdb->postmeta
table into this query:
function custom_posts_join($join){
global $wpdb;
$join .= " LEFT JOIN $wpdb->postmeta ON $wpdb->posts.ID = $wpdb->postmeta.post_id ";
return $join;
}
add_filter( 'posts_join' , 'custom_posts_join');