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.


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 />';

  • 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 clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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