Opened 17 years ago
Closed 17 years ago
#9214 closed defect (bug) (fixed)
wp_tag_cloud 'RAND' sorting broken if only one tag exist
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Milestone: | 2.8 | Priority: | normal |
| Severity: | normal | Version: | 2.7.1 |
| Component: | Template | Keywords: | has-patch commit |
| Focuses: | Cc: |
Description
This fault is only triggered if you have a blog where only one post has one tag defined. As soon as you add at least one more tag to any post the problem goes away.
The following query in wp_tag_cloud throws several warnings since it will cause WordPress to pass invalid arguments between internal functions in WordPress. If you use 'ASC' or 'DESC' sorting there is no problem.
wp_tag_cloud('format=array&orderby=name&order=RAND');
The following warnings are thrown:
PHP Warning: Invalid argument supplied for foreach() in ...../wordpress/wp-includes/category-template.php on line 663
PHP Warning: array_slice(): The first argument should be an array in ...../wordpress/wp-includes/category-template.php on line 670
PHP Warning: min(): Array must contain atleast one element in ...../wordpress/wp-includes/category-template.php on line 676
PHP Warning: max(): Array must contain atleast one element in ...../wordpress/wp-includes/category-template.php on line 677
PHP Warning: Invalid argument supplied for foreach() in ...../wordpress/wp-includes/category-template.php on line 689
This has been verified on two different WordPress setups where only one tag in one post has been defined.
When asking for 1 item returns from array_rand(), PHP returns a string, in the case of multiple results, then an array is returned. Casting to an array will work in both of these cases.
Candidate for 2.7.2