我有一个SQL查询,它正在构建一个wordpress帖子数组。。。
$query = "select $wpdb->posts.* from $wpdb->posts,$wpdb->terms,$wpdb->term_taxonomy,$wpdb->term_relationships where $wpdb->terms.term_id in (".$catId.") and $wpdb->terms.term_id = $wpdb->term_taxonomy.term_id and $wpdb->term_taxonomy.taxonomy = \'pcategory\' and $wpdb->term_taxonomy.term_taxonomy_id = $wpdb->term_relationships.term_taxonomy_id AND $wpdb->posts.post_status = \'publish\' and $wpdb->term_relationships.object_id = $wpdb->posts.ID and $wpdb->posts.ID != ".$post->ID." group by $wpdb->posts.ID order by $wpdb->posts.ID LIMIT 0 ,$limit";
我需要对此进行修改,以允许我添加一个条件,即数组中只包含具有特定自定义字段值的帖子,例如“Apple”。
有人能给我指出正确的方向吗?
更新我已尝试将其修改为。。。。
$query = "select $wpdb->posts.* from $wpdb->posts,$wpdb->terms,$wpdb->term_taxonomy,$wpdb->term_relationships where $wpdb->terms.term_id in (".$catId.") and $wpdb->terms.term_id = $wpdb->term_taxonomy.term_id and $wpdb->term_taxonomy.taxonomy = \'pcategory\' and $wpdb->term_taxonomy.term_taxonomy_id = $wpdb->term_relationships.term_taxonomy_id AND $wpdb->posts.post_status = \'publish\' and $wpdb->postmeta.meta_key = \'fruit\' and $wpdb->postmeta.meta_value= \'apple\' and $wpdb->term_relationships.object_id = $wpdb->posts.ID and $wpdb->posts.ID != ".$post->ID." group by $wpdb->posts.ID order by $wpdb->posts.ID LIMIT 0 ,$limit";
我假设这将缩小搜索范围,只搜索名为“fruit”的自定义字段值为“apple”但不起作用的帖子