Opened 17 years ago
Closed 17 years ago
#5155 closed defect (bug) (fixed)
wp_tag_cloud('format=array') does not return array
Reported by: | andrewflanagan | Owned by: | ryan |
---|---|---|---|
Milestone: | 2.5 | Priority: | low |
Severity: | minor | Version: | 2.3 |
Component: | Template | Keywords: | tags, tag cloud, array, has-patch |
Focuses: | Cc: |
Description
wp_tag_cloud('format=array'); will always return "Array" since the array is not returned but it merely attempts to "echo" the array (which in PHP will just output "Array"). I don't think that this is the intended purpose...
I had thought that the purpose of the parameter "format=array" was to get an actual PHP array of all tags. I can get this tag array by using get_terms('post_tag', $args);
I tried to slog through the code a little bit (wp-includes/category-template.php line 310 and on) but it didn't seem to handle the special case of not "echo"ing a result, but merely returning an array object.
Attachments (2)
Change History (11)
#1
@
17 years ago
- Summary changed from wp_get_tags to wp_tag_cloud('format=array') does not return array
#3
follow-up:
↓ 4
@
17 years ago
No, I gotta agree with the ticket. wp_generate_tag_cloud requires an input of tags from get_tags, which wp_tag_cloud does. Forcing them to use it directly adds more potential for error and doesn't necessarily allow for the result to always be the same data that wp_tag_cloud will create with the same parameters. So allowing format to be 'array' should return the array.
Anyway, it's an easy patch. Attached.
#4
in reply to:
↑ 3
@
17 years ago
- Milestone changed from 2.3.1 to 2.4
Replying to Otto42:
No, I gotta agree with the ticket. wp_generate_tag_cloud requires an input of tags from get_tags, which wp_tag_cloud does. Forcing them to use it directly adds more potential for error and doesn't necessarily allow for the result to always be the same data that wp_tag_cloud will create with the same parameters. So allowing format to be 'array' should return the array.
Anyway, it's an easy patch. Attached.
Thanks for that.
I guess I should have read the code a bit closer last night :-)
However that patch isn't quite correct I don't think.
Attaching a new one for testing.
#5
follow-up:
↓ 6
@
17 years ago
Why would you want to apply the wp_tag_cloud filters to an array?
Just wondering. Seems unlikely to me that any filters will be written to handle arrays properly there.
#6
in reply to:
↑ 5
@
17 years ago
Replying to Otto42:
Why would you want to apply the wp_tag_cloud filters to an array?
Just wondering. Seems unlikely to me that any filters will be written to handle arrays properly there.
I think we should always give the chance for a plugin to filter the output.
The plugin gets the $args string as a second argument to the filter call so it should be checking what it is getting before filtering anyway - otherwise it could break the output already if it applies filtering for flat displays to lists.
I think wp_tag_cloud is only designed to print out the tag cloud either as a flat list or with UL's. The array format that wp_generate_tag_cloud supports should only be used in calls to wp_generate_tag_cloud which does return the array.
This is an array of html links for the tags.
I think if anything you are calling wp_tag_cloud incorrectly.
Assigning to ryan for more input on this.