Make WordPress Core

Opened 16 years ago

Closed 15 years ago

#10221 closed feature request (wontfix)

Limit Categories by Parent

Reported by: utahcon's profile utahcon Owned by: filosofo's profile filosofo
Milestone: Priority: normal
Severity: normal Version: 2.8
Component: Taxonomy Keywords: wp_list_categories, number, categories, taxonomy
Focuses: Cc:

Description

Currently you can show the children of a particular taxonomy in wp_list_categories()

For these examples in the DB we have the following taxonomy

Books
   Good Books
   Bad Books
Cars
   Ugly Cars
   Pretty Cars
Horse
   Brown Horses
   Black Horses

example:

$cats = wp_list_categories('child_of=1');

this will return

$cats = Array(
   [0] 'Good Books'
   [1] 'Bad Books'
)

Showing a limited number of top level taxonomies is not possible

example:

$cats = wp_list_categories('number=2&child_of=0');

The expected results is:

$cats = Array(
   [0] Books
   [1] Cars
)

the actual result is:

$cats = Array(
   [0] Books
)

I would propose a new argument call parent

example:

$cats = wp_list_categories('parent=0&number=2');

which would return:

$cats = Array(
   [0] Books
   [1] Cars
)

Change History (4)

#1 @utahcon
16 years ago

I forgot to add that in the file wp-includes/taxonomy.php the following should be added to accomodate the parent filter:

if ( $parent ) {
     $hierarchy = _get_term_hierarchy($taxonomies[0]);
     if ( !isset($hierarchy[$parent]) )
          return $empty_array;
     }
}

#2 @Denis-de-Bernardy
16 years ago

  • Keywords close added
  • Milestone changed from Unassigned to 2.9

There already is a parent parameter for get_terms(). Please give it a shot and close the ticket, it should work out of the box.

#3 @Denis-de-Bernardy
16 years ago

  • Keywords reporter-feedback added

#4 @johnbillion
15 years ago

  • Keywords reporter-feedback close removed
  • Milestone 2.9 deleted
  • Resolution set to wontfix
  • Status changed from new to closed

wp_list_categories('depth=1&number=2') works too.

Note: See TracTickets for help on using tickets.