Make WordPress Core

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: rognilss's profile rognilss 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.

Attachments (1)

9214.diff (530 bytes) - added by DD32 17 years ago.

Download all attachments as: .zip

Change History (3)

@DD32
17 years ago

#1 @DD32
17 years ago

  • Component changed from General to Template
  • Keywords has-patch commit added; tag cloud rand removed

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

#2 @azaozz
17 years ago

  • Resolution set to fixed
  • Status changed from new to closed

(In [10636]) Fix wp_tag_cloud 'RAND' when only one tag, props DD32, fixes #9214

Note: See TracTickets for help on using tickets.