Make WordPress Core

Opened 13 years ago

Closed 13 years ago

Last modified 2 years ago

#7544 closed defect (bug) (invalid)

Multiple Category Handling Wrong

Reported by: zackdesign Owned by:
Milestone: Priority: normal
Severity: trivial Version: 2.6.1
Component: General Keywords: category, query_posts, categories, multiple, select
Focuses: Cc:


To create this problem I was doing the following:

  1. I created a plugin
  2. This plugin has an action call to 'init'
  3. The init function runs and then based upon a POST variable runs the following code:

query_posts(array('categoryin' => array($sql)));

  1. I've checked and tested $sql variable to ensure that it's passing the correct values.
  2. Testing further, it would appear that the implementation of categoryin is extremely haphazard. Sometimes it works, sometimes it doesn't. I'd like to request that this get fixed soon so that I don't have to resort to doing a custom query...!

What I want is for the user to select a set of categories and only show posts that span every single one of those categories. At the moment it shows the correct output sometimes and then other times shows the post even if there is one category it hasn't been added to. I have a setup of parent and child categories, with child categories used for the testing across parents.


parent 1

sub 1
sub 2

parent 2

sub2 1
sub2 2

I test across more than two parents and using categories like so: sub 1, sub2 2. I never choose multiple child categories under the one parent.

Hopefully this describes my problem in enough detail! You can see it an action currently at http://skopelostopos.net/ (see the drop-downs under Properties).

By the time you see it I may or may not have 1) fixed it using custom queries or 2) upgraded wordpress to the fix that I hope this ticket will engender...

Change History (4)

#1 @zackdesign
13 years ago

My apologies for the formatting:

query_posts(array('category__in' => array($sql))); 

#2 follow-up: @ryan
13 years ago

What's in $sql? category__in accepts an array of category IDs. If you want to do intersections, use category__and.

#3 in reply to: ↑ 2 @zackdesign
13 years ago

  • Resolution set to invalid
  • Severity changed from major to trivial
  • Status changed from new to closed

Replying to ryan:

What's in $sql? category__in accepts an array of category IDs. If you want to do intersections, use category__and.

$sql was a constantly changing text string modeled after: http://codex.wordpress.org/Template_Tags/query_posts#Category_Parameters

It would appear that this documentation is misleading. I just tried using a normal array and it worked perfectly!

#4 @DrewAPicture
6 years ago

  • Milestone 2.6.2 deleted
Note: See TracTickets for help on using tickets.