Make WordPress Core

Opened 14 years ago

Closed 14 years ago

Last modified 14 years ago

#21875 closed enhancement (wontfix)

get_categories orderby random

Reported by: Ninos Ego Owned by:
Priority: normal Milestone:
Component: Taxonomy Version: 3.4.2
Severity: trivial Keywords:
Cc: Focuses:

Description

There's no option to order the categories in the get_categories function by random..
Maybe you can include it in the next version.

get_posts etc. has got this option.

Change History (4)

#1 @scribu
14 years ago

  • Milestone Awaiting Review
  • Resolutionwontfix
  • Status newclosed

Unlike get_posts(), get_categories() doesn't have pagination, so you can just use shuffle():

$categories = get_categories();

shuffle( $categories );
Last edited 14 years ago by scribu (previous) (diff)

#2 follow-up: @Ninos Ego
14 years ago

Have used the shuffle function, but think, that my way brings a better performance..

#3 in reply to: ↑ 2 @nacin
14 years ago

Replying to Ninos Ego:

Have used the shuffle function, but think, that my way brings a better performance..

When you push randomization to SQL, it means we can't actually cache the results, as they're supposed to be random. get_posts() does pagination, which is why we push it to SQL — you need only X of Y posts, but a random X of them.

But get_terms(), as scribu said, isn't paginated. Thus, letting the query be cached, then shuffling them on your own, makes more sense.

#4 @Ninos Ego
14 years ago

ok thank you for the information..

Note: See TracTickets for help on using tickets.