I am trying to use the following command:

wp_set_object_terms( $myID, $myissuearray, 'my_issues', true );

But for some reason, it won't accept my variable array.

That array, $myissuearray, using error_log(print_r($myissuearray,true)) outputs:

    [0] => 9
    [1] => 10
    [2] => 77
    [3] => 12

Which sure looks like a valid array to me.

If on the other hand, I don't use my variable and set the issue array by hand in the command to something like:

wp_set_object_terms( $myID, array(9,10,77,12), 'my_issues', true );

the command works and the terms are set. I am stumped as to what I am doing wrong. Why won't this command accept my variable array??

  • how are you setting $myissuearray? also can you var_dump instead of print_r and show the result?
    – David Lee
    Feb 18, 2017 at 13:58
  • I JUST did that, and I notice they are strings, so I think that solves the mystery thanks. Now to figure out how to convert my string array to integers...
    – Stephen
    Feb 18, 2017 at 13:59
  • nice, please consider deleting the question or answering yourself
    – David Lee
    Feb 18, 2017 at 14:02
  • I will as soon as I figure out the rest, thanks...
    – Stephen
    Feb 18, 2017 at 14:02

1 Answer 1


Ok, so it turned out that my array was an array of strings somehow, which using var_dump (instead of print_r) revealed. Then I needed to convert my array to int values, which I did thus:

$myissuearrayINT = array_map('intval', $myissuearray);

And now, when I do the following it works as expected:

wp_set_object_terms( $myID, $myissuearrayINT, 'my_issues', true );

Hope this helps someone else out there...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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