#13246 closed defect (bug) (fixed)
wp_set_post_categories assumes $post_categories has a value in [0], but wp_insert_post doesn't assign the default category there
| Reported by: |
|
Owned by: |
|
|---|---|---|---|
| Priority: | normal | Milestone: | 3.0 |
| Component: | Taxonomy | Version: | 3.0 |
| Severity: | normal | Keywords: | has-patch needs-testing |
| Cc: |
Description
right now wp_insert post assigns the default category to a post just as an array item which should be in the 0 ofset. However this isn't guaranteed. If we cast it as the 0 offset in wp_insert_post, this solves the problem
To reproduce:
on a vanilla install with wp_debug enabled, add a post modifying the categories. This causes the following error: Notice: Undefined offset: 0 in /opt/lampp/htdocs/amun/wp/trunk/wp-includes/post.php on line 2561
Attachments (3)
Change History (10)
- Owner changed from filosofo to jorbin
- Status changed from new to assigned
- Keywords needs-testing added
I wasn't able to reproduce the notice. Could you provide more detailed steps to reproduce?
Anyway, 14438.diff:
- removes duplicated validation code from wp_insert_post()
- uses reset($post_category) instead of $post_category[0]
Replying to scribu:
I wasn't able to reproduce the notice. Could you provide more detailed steps to reproduce?
I get the error when only one category is checked before clicking Update
Undefined offset: 0 in \wp-dev\wp-includes\post.php on line 2574
- Resolution set to fixed
- Status changed from assigned to closed
Fixed. Thanks scribu and wpmuguru
comment:7
SergeyBiryukov — 5 months ago
#5096 was marked as a duplicate.

My first patch didn't solve it. For the second I added a check to make sure we have a category assigned in [0] if there is only one category.