我有 2 个分类法:city
和street
.
我需要获得postmeta
我的一个插件。
只有一种分类的工作代码:
SELECT *
FROM $wpdb->postmeta
LEFT JOIN $wpdb->posts ON($wpdb->posts.ID = $wpdb->postmeta.post_id)
LEFT JOIN $wpdb->term_relationships ON ($wpdb->postmeta.post_id = $wpdb->term_relationships.object_id)
LEFT JOIN $wpdb->term_taxonomy ON ($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id)
WHERE meta_key LIKE 'rwp_rating%'
AND ($wpdb->term_taxonomy.taxonomy = 'city'
AND $wpdb->term_taxonomy.term_id = '2')
但如果我附加
AND ($wpdb->term_taxonomy.taxonomy = 'street' AND $wpdb->term_taxonomy.term_id = '5')
它返回空结果。
我也尝试这样做:
SELECT *
FROM $wpdb->postmeta
LEFT JOIN $wpdb->posts ON ($wpdb->posts.ID = $wpdb->postmeta.post_id)
LEFT JOIN $wpdb->term_relationships ON ($wpdb->postmeta.post_id = $wpdb->term_relationships.object_id)
LEFT JOIN $wpdb->term_taxonomy AS t1 ON ($wpdb->term_relationships.term_taxonomy_id = t1.term_taxonomy_id)
LEFT JOIN $wpdb->term_taxonomy AS t2 ON ($wpdb->term_relationships.term_taxonomy_id = t2.term_taxonomy_id)
WHERE meta_key LIKE 'rwp_rating%'
AND (t1.taxonomy = 'city'
AND t1.term_id = '2')
AND (t2.taxonomy = 'street'
AND t2.term_id = '3331');
它也不起作用。
请注意:我需要同时匹配两者,例如:city = 2 AND street = 2
不是:city = 2 OR street = 2