WordPress.org

Make WordPress Core

Opened 11 years ago

Closed 11 years ago

Last modified 11 years ago

#4870 closed defect (bug) (wontfix)

Bug in get_categories when asking for category children

Reported by: hovenko Owned by: ryan
Milestone: Priority: high
Severity: major Version: 2.2.2
Component: General Keywords: categories
Focuses: Cc:

Description (last modified by foolswisdom)

When asking for categories that are child of another category (cat1) and to include empty categories I get different behaviour wether cat1 has children or not.

Take the following code:

$cat_children   = get_categories(
        array(
                'child_of'      => 1,
                'hide_empty'    => false,
        );
);

print_r($cat_children);

Scenario 1:
I have the following categories:

1 - cat1 (no parent)
2 - cat2 (no parent)
3 - cat3 (parent:1)

In this case it prints out cat3.

Scenario 2:
I have the following categories:

1 - cat1 (no parent)
2 - cat2 (no parent)

In this case it prints out cat1 and cat2.

Expected behaviour is to get an empty list, simply because cat1 doesn't have any children.

Attachments (1)

category.php.patch (378 bytes) - added by hovenko 11 years ago.
Patch for the file wp-includes/category.php

Download all attachments as: .zip

Change History (8)

#1 @foolswisdom
11 years ago

  • Description modified (diff)
  • Milestone changed from 2.2.3 to 2.3

#2 @ryan
11 years ago

  • Owner changed from anonymous to ryan

#3 @hovenko
11 years ago

I don't understand why the milestone was changed to 2.3. This is the time for fixing bugs, right? From my point of view, this is a bug.

I believe the fix is as simple as checking if both the category hierarchy is empty and "child_of" is set, then return an empty array.

@hovenko
11 years ago

Patch for the file wp-includes/category.php

#4 @DD32
11 years ago

I don't understand why the milestone was changed to 2.3. This is the time for fixing bugs, right? From my point of view, this is a bug.

2.3 is due on September 24th, There may be a 2.2.3 release before then, but i'm not sure. Since its dealing with Categories, and we've got a new category backend in 2.3, it'd make sense to simply focus the testing on the new stuff instead.

I cant reproduce the issue in 2.3 either, So it looks to me its fixed there.

2.3 Release Info: http://comox.textdrive.com/pipermail/wp-hackers/2007-August/013962.html

#5 @foolswisdom
11 years ago

  • Milestone changed from 2.3 to 2.2.3

DD32, thanks for testing this in 2.3! Since you say it doesn't repro, changing milestone back to 2.2.3 .

#6 @DD32
11 years ago

  • Resolution set to wontfix
  • Status changed from new to closed

Not an issue in 2.3, or 2.4(trunk), closing ticket.

#7 @lloydbudd
11 years ago

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