我在php语言之外查询wordpress mysql数据库,我不知道如何解决以下问题:每个帖子都有一些有价值的分类法。有一个名为“calificaciones'我想要过滤的。这是我目前的查询:
SELECT wp_posts.post_title, IF (wp_term_taxonomy.taxonomy = 'calificaciones', wp_terms.slug, 'no') as calificacion
FROM wp_posts
JOIN wp_term_relationships ON (wp_term_relationships.object_id = wp_posts.ID)
JOIN wp_term_taxonomy ON (wp_term_taxonomy.term_taxonomy_id = wp_term_relationships.term_taxonomy_id)
JOIN wp_terms ON (wp_terms.term_id = wp_term_taxonomy.term_id)
AND wp_posts.post_type = 'ultimas-noticias'
#AND wp_term_taxonomy.taxonomy = 'calificaciones'
此查询的问题在于我会多次获得post_title(因为每个帖子都有其他分类法)。如果帖子具有该分类值,我想获得帖子标题和标志是 - 否。
答案 0 :(得分:1)
您可以使用calificacion
列的子查询,而不是在同一查询中加入分类法。
SELECT wp_posts.post_title, CASE WHEN EXISTS((SELECT *
FROM wp_term_relationships
JOIN wp_term_taxonomy ON (wp_term_taxonomy.term_taxonomy_id = wp_term_relationships.term_taxonomy_id)
JOIN wp_terms ON (wp_terms.term_id = wp_term_taxonomy.term_id)
WHERE (wp_term_relationships.object_id = wp_posts.ID)
AND wp_term_taxonomy.taxonomy = 'calificaciones'
)) THEN 'YES' ELSE 'NO' END as calificacion
FROM wp_posts
WHERE wp_posts.post_type = 'ultimas-noticias'
答案 1 :(得分:0)
您可以使用select distinct
dat.1 #and the output will be all ASCII charaters
[1] "Work, Awareness, Potential"