WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] categories in wp_posts all show '0'? (8 posts)

  1. tdellaringa
    Member
    Posted 7 years ago #

    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?

  2. Chris_K
    Member
    Posted 7 years ago #

    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. http://codex.wordpress.org/Template_Tags/query_posts

  3. moshu
    Member
    Posted 7 years ago #

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

  4. tdellaringa
    Member
    Posted 7 years ago #

    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.

  5. tdellaringa
    Member
    Posted 7 years ago #

    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; ?>

  6. moshu
    Member
    Posted 7 years ago #

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

  7. tdellaringa
    Member
    Posted 7 years ago #

    Ahhh that was it! Thanks moshu! :)

  8. kurki15
    Member
    Posted 7 years ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Topic