下面应该可以做到这一点:
global $wpdb ;
// get the post_ids from the custom table
$sql = "SELECT listing_id FROM {$wpdb->prefix}wpdbdp_listing_fees WHERE fee_id = %d" ;
$sql = $wpdb->prepare ($sql, 4) ;
$post_ids = $wpdb->get_col ($sql) ;
// get the custom posts from the posts table
$args = array (
\'post__in\' => $post_ids,
\'post_type\' => \'wpbdp_listing\',
) ;
$posts = new WP_Query ($args) ;
foreach ($posts->posts as $the_post)
echo $the_post->post_title ;
}
注意使用
$wpdb->prefix
在SQL语句中。