WordPress.org

Support

Support » How-To and Troubleshooting » [Resolved] Exclude category from query_posts

[Resolved] Exclude category from query_posts

  • I’m having trouble with this, and have searched the Forum for about an hour. I see many ‘similar’ issues, but not this one in particular. I think my problem stems from the use of the array here (but, obviously, I’m not sure).

    I have this line of code in home.php

    <?php query_posts( array( 'post__not_in' => get_option( 'sticky_posts' ), 'paged' => get_query_var( 'paged' ) ) ); ?>

    I want to exclude the category with the ID ’10’

    How do I edit that query_post line to accomplish this?

    Thanks!

Viewing 15 replies - 1 through 15 (of 17 total)
  • esmi

    @esmi

    Forum Moderator

    <?php query_posts( array( 'post__not_in' => get_option( 'sticky_posts' ), 'paged' => get_query_var( 'paged' ), 'cat = -10' ) ); ?>

    Moderator Michael

    @alchymyth

    Forum Moderator

    Thanks for your reply esmi, but category 10 is still showing up in the main feed when I do it that way. I think I’m getting closer, using some info from that link, alchymyth, but not quite there yet. I’ve excluded category 10, but now the posts are showing up in reverse order (by date, oldest to newest). So I tried this:

    <?php query_posts( array( 'post__not_in' => get_option( 'sticky_posts' ), 'paged' => get_query_var( 'paged' ), 'orderby' => 'date', 'order' => 'ASC', 'category__not_in' => array( 10 ) ) ); ?>

    Still not affecting the order, whether I use ASC or DESC Showing up oldest-to-newest. I’m sure I’m missing something simple?

    esmi

    @esmi

    Forum Moderator

    The main feed? Are we talking about an RSS feed or a posts page?

    Sorry, main “posts page,” as in the main blog home page. I know I’m probably using incorrect terms!

    esmi

    @esmi

    Forum Moderator

    Try 'order' => 'DESC'

    Yeah, I’ve tried both ASC and DESC in that position, but it doesn’t change anything. The posts still show up oldest-to-newest. Weird.

    esmi

    @esmi

    Forum Moderator

    Is this the only query on the page or do you have other loops running?

    That is the only one.

    esmi

    @esmi

    Forum Moderator

    So nothing in other template files on the same page – such as sidebar.php, header.php etc?

    No, I even did a multi-file search of all the MAIN template files, as well as the CHILD template files (which I’m working on), and that is the ONLY instance of query_posts. It appears in home.php, and nowhere else :/

    esmi

    @esmi

    Forum Moderator

    Is this a custom page template?

    no, it’s a standard page template, and that’s the only line I’ve edited on that page.

    esmi

    @esmi

    Forum Moderator

    where did you download the theme from?

    It’s from Theme Hybrid http://themehybrid.com/

    Maybe I should start in their Forum next, and see if I can get something there…

Viewing 15 replies - 1 through 15 (of 17 total)
  • The topic ‘[Resolved] Exclude category from query_posts’ is closed to new replies.