Support » Fixing WordPress » SELECT only certain categories

  • How do make this select statement NOT select posts from the category 3? I mean what is the syntax, I have tried everything. I have my category 3 displayed separately, this is for my list of the 10 most recent posts on my right column.

    $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' AND post_date_gmt < '$today' ORDER BY post_date DESC LIMIT 10")):

    I tried this:

    AND post_category='photo_galleries

    but no worky!

Viewing 6 replies - 1 through 6 (of 6 total)
  • I know how to do the opposite like this:

    $myposts = get_posts(‘numberposts=10&offset=1&category=5’);

    and display one category, but how do I display all BUT one?

    $myposts = get_posts(‘numberposts=10&offset=1&category!=5’);

    doesn;t work with the (!) in there.

    You need query_posts, not get_posts.

    Query_posts doesn’t have an exclusion option, AFAIK.

    Yes it does. The least you could do is look it up.

    On that page it says:

    ” Excluding Multiple Categories

    Note: You cannot exclude more than one category with query_posts. Therefore you can use workarounds or plugins.”

    Those work arounds are what I am looking for. I have tried conditional loops and they do not work. I am not looking for an if_home function, this is for my sidebar, to only display titles, not the entire post.

    How about this:

    <?php query_posts('cat=-5'); ?>
    <?php if (have_posts()) : ?>
    <?php while (have_posts()) : the_post(); ?>
    <div class="rss" id="post-<?php the_ID(); ?>">
    <h1><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a></h1>
    <?php endwhile; ?>
    <?php endif; ?>

    That displays the correct list of posts in my sidebar but they all link to the post displayed on the main page, it is like the to query_posts interfere with eachother, is this the case?

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘SELECT only certain categories’ is closed to new replies.