我正在尝试并且未能获得具有以下条款的所有Term_Ids和名称:
特定类型(pa_height)并用于也使用已选择的已知term_taxonomy_id的产品
基本上我需要在wp_term_relationships中搜索具有特定term_id的所有产品,然后从这个产品列表中找到所有具有另一个类型(pa_height)的产品,最后获取这些pa_height术语的列表以填充第二个下拉列表。
当前的sql:表格和问题的大致轮廓:
$querystr = "
select *
from wp_term_taxonomy
join wp_term_relationships relation on relation.term_taxonomy_id = wp_term_taxonomy.term_id
left join (select * from wp_term_relationships where term_taxonomy_id = '23') prods on relation.object_id = prods.object_id
left join (select * from wp_term_taxonomy where taxonomy = 'pa_height') heights on relation.term_taxonomy_id = heights.term_id
";
表:
wp_term_relationships:
object_id(Product_Id) term_taxonomy_id(期限的ID) term_order(不适用)
wp_term_taxonomy
term_taxonomy_id term_id(与wp_term_relationships匹配term_taxonomy_id) 分类法(在这种情况下包含类型pa_height等)
wp_terms term_id匹配上面2个表中的term_id 名称 蛞蝓
我需要从所有具有我正在搜索的term_id的产品中获取term_id,来自wp_terms的名称。
我正在搜索单个术语ID(pa_width)并且需要所有具有此ID的产品,然后我需要使用此产品列表来输出他们所拥有的术语列表,只有当术语属于类型(pa_height)时最后将其链接到wp_term表以获取名称+ id
答案 0 :(得分:1)
排序,SQL非常激烈,左连接不起作用
现在根据所选的其他属性获取所需的属性。
在此发布以供将来参考:
select *
from wp_term_taxonomy
join wp_term_relationships relation on relation.term_taxonomy_id = wp_term_taxonomy.term_id
join (select * from wp_term_relationships where term_taxonomy_id = $width) prods on relation.object_id = prods.object_id
join (select * from wp_term_taxonomy where taxonomy = 'pa_height') heights on relation.term_taxonomy_id = heights.term_id
join wp_terms termies on termies.term_id = heights.term_id
group by wp_term_taxonomy.term_id
order by termies.name