WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top


I'am generating posts from an uploaded csv. Each row is supposed to be a new CPT record which will have a term based on one of its column. This is the stripped csv

Post Title;This is the content.;mars

This is supposed to create a CPT with the title "Post Title", and "This is the content." as the post content. The last part is supposed to set the post to the "mars" of the taxonomy "planets"

Somehow the script failed me.

So now I will have to search CPT - posts that are not related to any term of the "planets" taxonomy.


How to query posts that are not related to any term of a taxonomy?

Thank you in advance.

share|improve this question

Probably something like this:

$records = new WP_Query( array(
    'post_type' => array('record'),
    'post_per_page' => -1,
    ) );

while ( $records->have_posts() ) : $records->the_post();

  $terms = wp_get_post_terms( get_the_ID(), 'planets' );
  if ( count( $terms ) === 0 ) {
    echo 'Post ID: ' . get_the_ID() . '<br />';

share|improve this answer
That will do. But i hope there is WP_Query (without the count ($terms) conditional) / $wpdb trick to do it since I have 6000 ++ post to check. – ifdion Dec 26 '12 at 23:52
I don't know how it can be done. Someone with MySQL expertise might help you. – RRikesh Dec 27 '12 at 5:13

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.