我需要自定义查询来显示循环之外的帖子数。
结果需要过滤:
Taxanomy = ad_cat
Term_id = 32
Meta_key = cp_type
Meta_value = sale
Post-type = ad_listings
我有这个sql:
$query = "
SELECT *
FROM $wpdb->posts, $wpdb->postmeta
WHERE $wpdb->posts.ID = $wpdb->postmeta.post_id
AND $wpdb->terms.term_id = '32'
AND $wpdb->postmeta.meta_key = 'cp_tips'
AND $wpdb->postmeta.meta_value = 'Pārdod'
AND $wpdb->posts.post_status = 'publish'
AND $wpdb->posts.post_type = 'ad_listing'
";
但在这个查询中,我不知道如何添加术语:
术语 sql:
SELECT ID as PID FROM $wpdb->posts
LEFT JOIN $wpdb->term_relationships ON
($wpdb->posts.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 $wpdb->posts.post_status = 'publish'
AND $wpdb->term_taxonomy.taxonomy = 'ad_cat'
AND $wpdb->term_taxonomy.term_id = 32
如何把所有东西放在一起?