我正在尝试使用此查询同时搜索 wp_post 和 wp_postmeta:
$querystr = "
SELECT $wpdb->posts.*
FROM $wpdb->posts, $wpdb->postmeta
WHERE $wpdb->posts.ID = $wpdb->postmeta.post_id
AND $wpdb->postmeta.meta_key = 'City'
AND $wpdb->postmeta.meta_value = 'Vancouver'
AND $wpdb->posts.post_status = 'publish'
AND $wpdb->posts.post_type = 'talents'
ORDER BY $wpdb->posts.post_date DESC
";
$pageposts = $wpdb->get_results($querystr, OBJECT);
如您所见,我搜索以 City=Vancouver 作为元字段的帖子。但是我如何再添加一个条件,这样我就不会把温哥华,不列颠哥伦比亚省和温哥华,WA 放在一起?
之类的:
AND ($wpdb->postmeta.meta_key = 'Country'
AND $wpdb->postmeta.meta_value = 'Canada')
AND ($wpdb->postmeta.meta_key = 'City'
AND $wpdb->postmeta.meta_value = 'Vancouver')