Support » Fixing WordPress » categories in wp_posts all show ‘0’?

  • Resolved tdellaringa


    Hi there,

    Let me first say my site is working just fine. However, I want to make a static page pulling the titles of all posts in one particular category (audio). I figured I would modify one of the BX_ functions to do that, and make my own function to pull the list.

    Seems simple enough so I looked up the category # I wanted, which was 9. However when I took a peek in wp_posts and looked at the post_category column – they are *all* 0’s, all the way down!

    How can this be – my categories work fine. But if the category numbers are not in posts, how can filter and pull only those posts?

    I was going to use this line:

    $posts = $wpdb->get_results(“SELECT ID, post_title FROM ” . $wpdb->posts . ” WHERE post_status=’publish’ AND post_category=’9′ ORDER BY post_date DESC LIMIT ” . $limit);

    But now I am stuck… is the 0 just a placeholder or something or is something wrong with my table?

Viewing 7 replies - 1 through 7 (of 7 total)
  • Did you notice the wp_post2cat table? You’ll want to join that one in on your query.

    You might also look at query_posts in conjunction with The_Loop.

    I guess the data you are looking for is stored in the post2cat table.
    But I have no idea how to write code 🙁

    Ok, so wp_post2cat is an intersection table, I see it now. I assume post_category is legacy code. Thanks, I’ll try a join and see if it works.

    Ok, after reading the codex it made more sense to just make a wordpress page using the loop and query_posts(), which I did, and it works, but strangely only gives me 5 results and nothing else. Yet I look in the database, and the category_count is 52! Why 5 and not all 52? Here is the code in my page:

    <?php query_posts(“cat=9&order=ASC”); ?>

    <?php if (have_posts()) : ?>

    <?php while (have_posts()) : the_post(); ?>

    <open anchor tag>”><?php the_title(); ?></end anchor tag>

    <?php endwhile; ?>

    <?php endif; ?>

    I bet you have 5 set in Options > Reading. That applies to everything – unless you specify it otherwise in your query above.

    Ahhh that was it! Thanks moshu! 🙂



    I think this post has me partially on track to where I want to go, but I’m not very PHP comfortable, so please forgive me. If there is another thread elsewhere that addresses my question please point me there. I haven’t been quite sure how to search for what I’m wishing to do…

    Now that 2006 has come to end I’m wanting to create some static pages that are summaries from the past year. My blog is more or less a craft blog with some book, music and movie reviews thrown in. So, I’d like pages that show my completed projects for a given type of craft, or that gathers all my book reviews for 2006 on a page.

    For example, I’d like to create a static WP page that list all posts that fall under both the categories of “Finished Objects” (id=22) AND “Sewing” (id=37) (meaning only those posts that are marked with both categories show, so the intersection of 22 and 37) and are dated with the year=2006.

    It was also mentioned that you needed to override the Options > Reading setting in the query to be able to display all of them (most counts matching multiple categories for me would be loadable in a reasonable amount of time, but more than my current setting of 5 which I like for the front page of the blog). How do I do that?

    Oh, and if you know of a plug-in that will aid in what I’m wishing to do I’m fine installing one. I just wasn’t finding any…

    Thank you in advance for any light you can shed on my dilemma.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘categories in wp_posts all show ‘0’?’ is closed to new replies.