我正在使用自定义分类法系列来跟踪系列中的帖子。我想找到没有系列的帖子。我有以下疑问:
global $wpdb;
$pr = $wpdb->prefix;
$sql_no_series=
"Select
*
from
wp_term_taxonomy tt,
wp_term_relationships tr,
wp_posts p
WHERE
tt.term_taxonomy_id=tr.term_taxonomy_id AND
tr.object_id=p.ID AND
p.ID NOT IN
(Select
p.ID
from
wp_term_taxonomy tt,
wp_term_relationships tr,
wp_posts p
WHERE
tt.term_taxonomy_id=tr.term_taxonomy_id AND
tr.object_id=p.ID AND
tt.taxonomy=\'series\')
AND tt.term_taxonomy_id = $category ";
$no_series = $wpdb->get_results($sql_no_series,ARRAY_A);
有没有一种方法可以使用WP\\u查询来完成?
SO网友:Glenn Forrest
Emily的回答基本上是正确的,只是操作符中不应该有下划线:
$args = array(
\'post_type\' => \'my_post_type\',
\'tax_query\' => array(
array(
\'taxonomy\' => \'series\',
\'operator\' => \'NOT EXISTS\',
),
),
);
$query = new WP_Query( $args );