Opened 14 years ago
Closed 14 years ago
#15442 closed defect (bug) (fixed)
Indexes no longer start at 0 for get_the_category()
Reported by: | ramenboy | Owned by: | |
---|---|---|---|
Milestone: | 3.1 | Priority: | normal |
Severity: | normal | Version: | 3.1 |
Component: | General | Keywords: | has-patch |
Focuses: | Cc: |
Description
Due to changes related to #15407, it seems that the keys in the array returned by get_the_category() are now category IDs instead of being 0-based. As a result, code such as the following now breaks:
<?php
$category = get_the_category();
echo $category[0]->cat_name;
?>
The above usage is from the docs: http://codex.wordpress.org/Function_Reference/get_the_category
Attachments (2)
Change History (12)
#3
@
14 years ago
- Cc gazouteast added
Possibly related, but certainly a side effect
http://wordpress.org/support/topic/yet-another-category_id-how-to-thread?replies=1
Multiple issues surfacing -
$category = get_the_category(); = fails to get the category ID numbers
echo $category[0]->cat_name; = (tested on two different servers now) the " -> " is being read as the closer for a " <!-- " HTML comment tag.
The context I'm trying to use this in, is in the sidebar, in a widget, to grab the category ID number and assign it to a variable for use in a function call. In this instance, it's a new build where the category number, Adrotate group and block, and the NextGEN gallery ID numbers are all synchronised such that ID 1 = name Art in all cases. But, the category ID call is failing and blocking the build from progressing.
I'm not submitting this as a support shout, but rather to give you an instance of failure. The initial ticket report now gives me a clue as to why.
#7
@
14 years ago
If we do decide to use array_values(), maybe it should be called further down, in get_the_terms() ?
Don't you think it would be better just to change the docs?