Support » Fixing WordPress » Posts with NO category

  • Hello-

    I have a situation where a syndication is bringing in posts that are fed to a wordpress with NO category. I’m not talking about them coming in and being filed under the “uncategorized” category but NO category at all.

    I’d like a way to exclude these from the loop, but without an ID to work with I’m a little lost on which way to go. Any suggestions?

Viewing 15 replies - 1 through 15 (of 15 total)
  • Hi jwind. I believe I had an idea of what is going on, but I’m not 100%. Can you respond back with more details, such as the link that is coming in and where you would want it to go?

    Also, do you have access to a MySQL GUI, such as phpMyAdmin? That will be helpful in finding the ID of an article.


    – Brad

    Yes I have phpMA access, but there is NO category to search for and it’s not listed in the DB.

    To over simplify things.

    Posts come in via feed and SOME have no category at all – hence no ID.

    Hi jwind,

    I’m still a little confused.

    Is the syndication linking to but not including a post number? Or is it linking to instead of

    Are you able to give us a specific example?

    – Brad

    The syndication links to the local Post. I can’t link to it as there is a privacy policy in place. Sorry.

    Thanks for getting back with me jwind. I wish I could help, but I’m feeling like I’m hitting a brick wall. Can you give a type of example? Instead of your domain, can you replace it with and give us an example?

    For example:
    – Syndication links to instead of

    It doesn’t have to do with the syndication link. These posts are LOCAL.

    That being said, they fed via and RSS 2.0 feed. Some from blogger, some from others… IF they have designated a category then it’s applied when imported into my WP install and everything is honky dory.

    What I’d like to be able to do is omit the posts that come in uncategorized in my loop but can’t if I don’t have an ID… Or at least can’t think of a way…

    Hi jwind, thanks for your patience.

    Are familiar with php?

    If I understand you correctly, while you’re going through the WordPress loop to display each post, you can put in a conditional statement that logically matches:

    if the post has a designated category, then display it, otherwise skip over it and move on to the next post.

    You may be able to use one of these functions to test to see if there is a category:

    Does it sound like we’re getting on the right track, or am I not understanding your request?

    Yes, absolutely. I want nothing more to write a conditional statement BUT how do I exclude these posts without an ID?

    <?php if ( have_posts() ) && !category ID : ?>
    blah blah blah…

    Alright jwind, I think I got it for you!

    The file I’m editing is loop.php, found in my particular theme’s folder.

    For testing, if you wanted to simply print out the category info for the post, update the code so it looks like this:

    <?php while ( have_posts() ) : the_post(); ?>
    <?php /* How to display posts of the Gallery format. The gallery category is the old way. */ ?>
    $this_post_category_info = get_the_category();
    echo "<pre>"; print_r($this_post_category_info); echo "</pre>";

    What I did is created a new category called “newcategory”. If the post did not belong to that category, then I wouldn’t display the post. I accomplished this by:

    <?php while ( have_posts() ) : the_post(); ?>
    <?php /* How to display posts of the Gallery format. The gallery category is the old way. */ ?>
    $this_post_category_info = get_the_category();
    if($this_post_category_info[0]->name != "newcategory")
            // do not print this post

    What you can do is modify the above so that instead of testing for a category name of “newcategory”, you can test to see if the category is null, as in:

    Does this help? We’re almost there!

    Test to see if a category is null. Perfect. I knew we were over complicating this… Not sure why i didn’t think about this earlier. Thanks.

    Hi jwind, I’m glad we were finally able to get this resolved! Let me know if you have any trouble implementing that code in your site.

    Hi, I’m really glad I stumbled across this post. I am actually trying to do the exact opposite, but I don’t know enough php to understand the link about checkin if is_null. However, what I want to do is only display posts where is_null is TRUE.

    The backstory; I work for a school and all the teachers have author pages; their is no category for their general newsletter…So, I want to filter out all the things that are categorized (like home work, etc.), only leaving me with the null category posts for each teacher.

    Any help on this would be amazing.

    Thank you,

    Moderator bcworkz


    Untested, but I gather from your explanation, you would alter the above code snippets as follows:

    <?php while ( have_posts() ) :
            $this_post_category_info = get_the_category();
            if( is_null( $this_post_category_info[0]->name )) {
    endwhile; ?>

    Assuming you are running a query for each teacher. My main point is illustrating how to use is_null() in the above context.


    Thank you for that, but I must still be doing something wrong. I am running a query for each teacher before the code you gave above. However, it is still only displaying the most recent posts (category or not). Obviously, I only want the post without a category.
    Here is my code:

    <?php while ( have_posts() ) :
           						$this_post_category_info = get_the_category();
            					if( is_null( $this_post_category_info[0]->name )) {
    								echo '<h1>';
    								echo '</h1>';
            					} endwhile; ?>
                            <?php wp_reset_query(); ?>

    I went back and read my earlier post, I realize I may not have been specific enough. All these posts come from various custom post types (each grade has a separate post type). Because all these posts are in a custom post type, each category I’m referring to is a custom taxonomy; is it possible WordPress doesn’t think any of them have a category because they are custom taxonomies?

    Thank you for your help,

    Ok, so I’ve done a bunch of new research because I realize I don’t think I have been looking for the right thing. I keep using the word “category” not “taxonomy” and “terms”.

    I have since figured out what I am trying to do is show all post by an author from every customs post type that have no terms selected within their taxonomy. So, the code I have been given is very close, but what I need is a function other than get_the_category, as it is too specific. I need a more general get_the_terms. I did research on that function, but I can’t figure out how it works.

    The codex page is here.

    I have been working off the second example as I need it to figure out the post id so that it can then determine if it has a term or not (using the is_null). So my function is essential the same as in the example. What I’m can’t figure out is how to modify the function to give me a term in a way that I can use with the is_null.

    I hope that made more sense.

    Thank you,

Viewing 15 replies - 1 through 15 (of 15 total)
  • The topic ‘Posts with NO category’ is closed to new replies.