WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] How to exclude category in WP_Query(); (5 posts)

  1. c-bass
    Member
    Posted 6 years ago #

    how can i exclude a category in
    $my_query = new WP_Query('category_name=neuigkeiten&showposts=1'); ???

  2. Samuel Wood (Otto)
    Tech Ninja
    Posted 6 years ago #

    Instead of category_name, just use cat. You can exclude category #4 like so: cat=-4

  3. c-bass
    Member
    Posted 6 years ago #

    thhhhhhhhhhhhhhhhhaaaanx

  4. Ingenius Dastard
    Member
    Posted 5 years ago #

    But this excludes posts that belong to a category. What if I have a post that belongs to another "main" category but also belongs to the excluded category as a secondary category.

    Is there any way to use "cat" as a secondary category only?

    Thanks.

  5. Meitar
    Member
    Posted 5 years ago #

    @ipruthi:

    Is there any way to use "cat" as a secondary category only?

    I am trying to do something similar with an algorithm I thought would be able to be flexible enough to allow arbitrary exclusions. It used to work in 2.5.1 but seems broken in 2.6.

    I posted a help topic about this but have yet to receive feedback. Maybe the answer to my problem will also help you?

Topic Closed

This topic has been closed to new replies.

About this Topic