Opened 10 years ago
Closed 10 years ago
#29629 closed defect (bug) (fixed)
Shortcode playlist random order parameter can't work
Reported by: |
|
Owned by: |
|
---|---|---|---|
Milestone: | 4.1 | Priority: | normal |
Severity: | major | Version: | 4.0 |
Component: | Media | Keywords: | has-patch |
Focuses: | Cc: |
Description
The parameter RAND
for the argument order
gets replaced with none
1246 if ( 'RAND' == $atts['order'] ) { 1247 $atts['orderby'] = 'none'; 1248 }
see: https://core.trac.wordpress.org/browser/trunk/src/wp-includes/media.php#L1246
Which gets passed to get_posts()
and won't give back a random order
RAND
should be replaced by rand
- like this:
1246 if ( 'RAND' == $atts['order'] ) { 1247 $atts['orderby'] = 'rand'; 1248 }
than it works perfectly fine.
Discovered while answering a question at WPSE
http://wordpress.stackexchange.com/q/161084/22534
Attachments (2)
Change History (9)
#1
@
10 years ago
- Component changed from Shortcodes to Media
- Keywords needs-patch added
- Milestone changed from Awaiting Review to 4.1
#4
in reply to:
↑ 2
@
10 years ago
- Severity changed from normal to major
Replying to Otto42:
These lines can be removed entirely. I don't know why they're in the gallery shortcode or in this shortcode, but they're perfectly useless:
if ( 'RAND' == $atts['order'] ) { $atts['orderby'] = 'none'; }
They aren't just useless. They serve as a mine trap. Nice how fast you patched it.
#5
follow-up:
↓ 6
@
10 years ago
Turns out, this is even messier - passing 'orderby' => 'rand'
creates queries withRAND() DESC
in them.
I made more changes in 29629.2.diff and added some unit tests.
#6
in reply to:
↑ 5
@
10 years ago
Replying to wonderboymusic:
Turns out, this is even messier - passing
'orderby' => 'rand'
creates queries withRAND() DESC
in them.
Not surprised, but then I'm inclined to say "who cares"... unless you can show that RAND() DESC is any slower or faster than RAND() ASC. I'm pretty sure that mySQL won't have any difference here.
And even in that case, I think that's probably better suited for another ticket, one more specifically related to improving the performance of WP_Query.
It appears that some of this was copied from the gallery shortcode and that the documentation was written somewhat incorrectly.
In short, this is wrong:
To get a random order, the "orderby" parameter should be set to "rand" and the value of the "order" parameter is somewhat irrelevant. It can be ASC or DESC, but it's just sorting random numbers at that point.
These lines can be removed entirely. I don't know why they're in the gallery shortcode or in this shortcode, but they're perfectly useless:
And the documentation in the function header should reflect that "orderby" is what can be "rand", not "order". These values are passed through to the same values in WP_Query, and the parse_query() function there correctly documents their usage.