• I select posts from every category, of a custom post type, now I need to display only the ones that have no category. How does that happen?

    Should I iterate over all posts and check if they have a taxonomy slug?

Viewing 8 replies - 1 through 8 (of 8 total)
  • Hi,

    If I’m not mistaken, WP automatically assigns the category “uncategorized” to posts without categories. Just get the ID number of the uncategorized category from the Admin Panel -> Posts -> Categories, and use query_posts with a cat argument.

    Cheers!

    Yes, WordPress does its best not to let a post be “not in any category” but rather puts them in the category of Uncategorized. That really should be handled differently… one day

    The posts get assigned to your default category, which is by default, “uncategorized”. But you can change the default cat and delete uncategorized if you’d like.

    Thread Starter d0100

    (@d0100)

    I managed to do what I wanted, I just got all posts, printed out the ones with categories, and the rest treated as uncategorized.

    This doesn’t work with user taxonomies if these are not managed similarly. So the question still stands: how to get posts that have NO association with any of the terms of particular taxonomy?

    maybe excluding all categories from query :

    $args = array(
    	'tax_query' => array(
    		array(
    			'taxonomy' => 'category',
    			'field' => 'id',
    			'terms' => array( /* all_categories_ids */ ),
    			'operator' => 'NOT IN',
    		)
    	)
    );

    http://codex.wordpress.org/Class_Reference/WP_Query#Taxonomy_Parameters

    Hi s.holyszewsky,

    I think your pb might constitute a different issue from the OP’s. The OP’s issue is about querying posts that don’t have categories assigned to them, and that question has already been answered.
    If you want to get all untagged posts, you can take a look at this.
    If you would like to do the same thing with custom taxonomies, and advanced taxonomy query might be your answer. Take a look at Otto’s post regarding this matter.
    That’s pretty much all I can tell you without further information about what you are trying to accomplish exactly.
    Good luck.

    I have found something similar to this here:

    http://wordpress.org/support/topic/posts-with-no-category?replies=13#post-2960241

    I am trying to do the opposite, I only want to show post that don’t have a category by specific authors. I think the above link is very close with by checking the is_null(), but I don’t understand how to use it. My thought is if you check if a category is null it is just a matter of using an else statement to get it to do what I want. However, I can’t get the is_null() to work (but that is because of my lack of knowledge.

    Thoughts?

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Get posts that have no category’ is closed to new replies.