WordPress.org

Ready to get started?Download WordPress

Forums

Exclude category from query_posts (18 posts)

  1. elmnt
    Member
    Posted 2 years ago #

    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!

  2. esmi
    Forum Moderator
    Posted 2 years ago #

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

  3. alchymyth
    Forum Moderator
    Posted 2 years ago #

  4. elmnt
    Member
    Posted 2 years ago #

    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?

  5. esmi
    Forum Moderator
    Posted 2 years ago #

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

  6. elmnt
    Member
    Posted 2 years ago #

    Sorry, main "posts page," as in the main blog home page. I know I'm probably using incorrect terms!

  7. esmi
    Forum Moderator
    Posted 2 years ago #

    Try 'order' => 'DESC'

  8. elmnt
    Member
    Posted 2 years ago #

    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.

  9. esmi
    Forum Moderator
    Posted 2 years ago #

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

  10. elmnt
    Member
    Posted 2 years ago #

    That is the only one.

  11. esmi
    Forum Moderator
    Posted 2 years ago #

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

  12. elmnt
    Member
    Posted 2 years ago #

    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 :/

  13. esmi
    Forum Moderator
    Posted 2 years ago #

    Is this a custom page template?

  14. elmnt
    Member
    Posted 2 years ago #

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

  15. esmi
    Forum Moderator
    Posted 2 years ago #

    where did you download the theme from?

  16. elmnt
    Member
    Posted 2 years ago #

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

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

  17. esmi
    Forum Moderator
    Posted 2 years ago #

    I think that would be a good idea. It's a pretty complex theme and they are the experts.

  18. elmnt
    Member
    Posted 2 years ago #

    Thanks for your time and help, I appreciate it!

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags