[closed] Display All But One Category (3 posts)

  1. thebindlestick
    Posted 9 years ago #

    I have a three column layout, WP 2.1 running all the latest PHP and MySQL installs. On my right column I have code that displays the 10 most recent posts...

    <h1><?php _e("Recent Stories"); ?></h1>
        $today = current_time('mysql', 1);
        if ( $recentposts = $wpdb->get_results
        ("SELECT ID, post_title FROM $wpdb->posts
        WHERE post_status = 'publish' AND
        post_type='post' ORDER BY post_date DESC
        LIMIT 10"));
        foreach ($recentposts as $post) {
        if ($post->post_title == '')
        $post->post_title = sprintf(__('Post #%s'), $post->ID);
        echo "<li><a href='".get_permalink($post->ID)."'>";
        echo '</a></li>';

    ...and it works perfect. However, I also display category 5 in a list below that, and want to exclude it from the query above. How can I do this? I have tried LEFT JOIN with other tables but I just cannot seem to get this to work. I would rather it be exclusive (exclude one category) rather than inclusive (include everything else) because our site is pretty bug and I do not want to list out a comma separated list of all categories TO use, make sense? Any advice would be appreciated.

  2. moshu
    Posted 9 years ago #

    Slow down and keep it in one single topic!
    How many times will you ask thje same question in different new topics?

  3. Firas
    Posted 9 years ago #

    If you're familiar with LEFT JOIN... you need to cross reference the post_ID with the one in post2cat

Topic Closed

This topic has been closed to new replies.

About this Topic