WordPress.org

Ready to get started?Download WordPress

Forums

Logical AND .... "? cat=x&cat=y" (13 posts)

  1. duke556
    Member
    Posted 9 years ago #

    Hi community or whoever reads this,
    I´ve got a question resp. the behaviour of the query.
    Trying to use two category expressions in one query, e.g. index.php?cat=11&cat=12 does neither work as OR or AND but yields only the last "cat"-expression, in this case all posts in "12". I would like to know whether it´s possible to have the above query getting to work as Logical AND function, giving back only those entries that belong to both those categories .
    Thanks for any (valuable) input !
    Jonas / Germany

  2. chuyskywalker
    Member
    Posted 9 years ago #

    try cat=12,13

  3. duke556
    Member
    Posted 9 years ago #

    Thanks for the reply, but the function only reads the one value after the "=" in the query...Helpful would be some insight given to me by some WP-crack whether "AND" for 'n' cat queries is working at all or how it could be enabled..

  4. ringmaster
    Member
    Posted 9 years ago #

    The method that chuyskywalker described works but does an OR on the categories. So cat=11,12 would display posts from categories 11 or 12.
    As far as I know, there isn't a way to diplay only posts that belong to two specific categories. Are you sure you want what you're asking for? This would be like asking for posts from "Football" and "Vacation" categories.

  5. duke556
    Member
    Posted 9 years ago #

    Well, a Select of post in two disjunct categories is quite important for my purposes. I am maintaining a business weblog and make very extensice use of categories. I have for instance news items that stem from a specific country, contain news of a specific supplier or contain business figures . Being able to use a .php?cat=n&cat=y&cat=z query would enable me (and others with a similar subject) to build a very interesting category-based search.
    Thx for follow up

  6. DennisWilliamson
    Member
    Posted 9 years ago #

    Try using a plus sign:
    index.php?cat=11+12

  7. duke556
    Member
    Posted 9 years ago #

    Thanks for reading&replying, but I am afraid that does not work either...but thx anyway

  8. TechGnome
    Moderator
    Posted 9 years ago #

    in the top of you index.php, right after the notice about not removing these lines, try this:

    if (!isset($cat)) {
    $cat = "x,y";
    }

    Where x & y are the category numbers you do want shown.
    See if that works for you.
    TG

  9. DennisWilliamson
    Member
    Posted 9 years ago #

    Hmmm...
    I just tested mine (1.2) again and I can do
    index.php?cat=2+3
    or
    index.php?cat=3+8+9+11
    and it works perfectly.
    Dennis

  10. sts
    Member
    Posted 9 years ago #


  11. dooglio
    Member
    Posted 7 years ago #

    I just tried it, and it does not work for me, either. BTW: I'm very interested in having this feature because I use the blog engine as a sort of poor-man's bug tracker. Consequently, I need ANDing of categories.

    However, I don't think I'm running the latest version, so that could be it...?

  12. Kafkaesqui

    Posted 7 years ago #

    dooglio, using either

    ?cat=1,2,3

    or

    ?cat=1+2+3

    to combine category queries has worked from the start. Keep in mind if one of the queried categories has the lion's share of recent posts, that can make it appear as if it doesn't work.

  13. tengil
    Member
    Posted 7 years ago #

    Well, ?cat=1,2,3 and ?cat=1+2+3 does the same thing for me. And that's not what he's asking for.

    I too need to be able to get the posts that belong to, say, both cat 2 and 7. I don't want those that only has cat 2, or only cat 7, but those that has both.

    Example:

    Let's say I have categories HOWTO (1) and GIMP (2) and AMAROK (3). Some posts are about GIMP or AMAROK in general, some are GIMP HOWTOs and some might also be AMAROK HOWTOs.

    Now, what I want is GIMP HOWTOs. Asking for ?cat=1+2 gives me all GIMP postings and all HOWTO postings (including AMAROK stuff). How can I get just the postings belonging to both GIMP and HOWTO?

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags