WordPress.org

Make WordPress Core

Opened 19 months ago

Closed 19 months ago

Last modified 19 months ago

#21875 closed enhancement (wontfix)

get_categories orderby random

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

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)

comment:1 scribu19 months ago

  • Milestone Awaiting Review deleted
  • Resolution set to wontfix
  • Status changed from new to closed

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

$categories = get_categories();

shuffle( $categories );
Version 0, edited 19 months ago by scribu (next)

comment:2 follow-up: Ninos Ego19 months ago

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

comment:3 in reply to: ↑ 2 nacin19 months 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.

comment:4 Ninos Ego19 months ago

ok thank you for the information..

Note: See TracTickets for help on using tickets.