[wp-trac] [WordPress Trac] #5096: wp_set_post_categories fails if
input array index starts with other than 0
WordPress Trac
wp-trac at lists.automattic.com
Thu Sep 27 19:55:13 GMT 2007
#5096: wp_set_post_categories fails if input array index starts with other than 0
---------------------+------------------------------------------------------
Reporter: borgar | Owner: anonymous
Type: defect | Status: new
Priority: normal | Milestone:
Component: General | Version: 2.3
Severity: normal | Keywords:
---------------------+------------------------------------------------------
wp_set_post_categories is defected in that if it is passed a an array of
categories who's index starts at other than 0, it returns without any
action. I noticed this when tracking another issue in Textpattern import.
Example:
{{{
$cats = array();
$cats[1] = 10;
wp_set_post_categories($postID, $cats);
}}}
This fails because {{{(1==count($cats) && ''==$cats[ 0 ]) == true}}}.
Further, I feel that inconsistent checking behavior needs addressing. Why
should this function return true in the single case where it gets an array
of values where {{{[0]==''}}} ?
My suggestion is to use this:
{{{
if (!is_array($post_categories) || '' == implode($post_categories))
$post_categories = array(get_option('default_category'));
}}}
--
Ticket URL: <http://trac.wordpress.org/ticket/5096>
WordPress Trac <http://trac.wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list