I am using a custom taxonomy series to keep track of posts that are in a series. I would like to find the posts that do not have a series. I have the following query:
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);
Is there a way to do it using WP_Query?
I am using a custom taxonomy series to keep track of posts that are in a series. I would like to find the posts that do not have a series. I have the following query:
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);
Is there a way to do it using WP_Query?
Share Improve this question asked Jun 8, 2016 at 19:17 pppppppp 1012 bronze badges2 Answers
Reset to default 3Emily's answer is mostly correct, just that the operator shouldn't have an underscore in it:
$args = array(
'post_type' => 'my_post_type',
'tax_query' => array(
array(
'taxonomy' => 'series',
'operator' => 'NOT EXISTS',
),
),
);
$query = new WP_Query( $args );
Something like this should work, where series is the taxonomy name and not a option within a taxonomy:
$args = array(
'post_type' => 'my_post_type',
'tax_query' => array(
array(
'taxonomy' => 'series',
'operator' => 'NOT_EXISTS',
),
),
);
$query = new WP_Query( $args );
reference with plenty of code examples: https://codex.wordpress/Class_Reference/WP_Query#Taxonomy_Parameters
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745180454a4615393.html
评论列表(0条)