WordPress.org

Ready to get started?Download WordPress

Forums

Get posts that have no category (9 posts)

  1. d0100
    Member
    Posted 2 years ago #

    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?

  2. Marventus
    Member
    Posted 2 years ago #

    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!

  3. wlindley
    Member
    Posted 2 years ago #

    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

  4. markparolisi
    Member
    Posted 2 years ago #

    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.

  5. d0100
    Member
    Posted 2 years ago #

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

  6. s.holyszewski
    Member
    Posted 2 years ago #

    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?

  7. Seebz
    Member
    Posted 2 years ago #

    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

  8. Marventus
    Member
    Posted 2 years ago #

    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.

  9. Anthony D'Arco
    Member
    Posted 2 years ago #

    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?

Topic Closed

This topic has been closed to new replies.

About this Topic