0

I'm trying to use wp_set_object_terms ref : http://codex.wordpress.org/Function_Reference/wp_set_object_terms while passing array for both the terms and taxonomy

for some reason i keep getting : Warning: Illegal offset type in isset or empty in /home1/stodeckc/public_html/clicktranslate/wp-includes/taxonomy.php on line 231

this is how i am trying to set it:

parents[] = array(
    'item_id' => 15,
    'app_name' => 'justanotherone'
);

foreach($parents as $parent){
    $cat_ids[$parent['item_id']] = (int)$parent['item_id'];
    $taxonomies[$parent['item_id']] = $parent['app_name'];
}
wp_set_object_terms( 42, $cat_ids,$taxonomies);

am i missing something ?

Thanks

2
  • Why are you setting the array index?
    – eteich
    Jan 29 '14 at 21:56
  • The warning message shows the $taxonomies you pass to wp_set_object_terms might be empty or wrong type. Could you dump the $cat_ids and $taxonomies to see what are the values?
    – 1fixdotio
    Jan 30 '14 at 1:10
1

what i ended up doing:

foreach($this->parents as $parent){
            $taxonomies[] = $parent['app_name'];
        }
        wp_delete_object_term_relationships( (int)$parent['item_id'], array_unique( $taxonomies ) );

        foreach($this->parents as $parent){
            $cat_id = (int)$parent['item_id'];
            $taxonomy = $parent['app_name'];
            wp_set_object_terms( (int)$parent['item_id'], $cat_id,$taxonomy, true);
        }

This solution is a little longer but it worked and i couldn't spend more time searching the problem.

Thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.