This may just be a 5PM Friday issue, but I'm scratching my head over here. I'm trying to associate a string of related entry id's represented by a variable with a new entry via the API. When I pass the variable, only the first one gets inserted into the DB. If I use the string they all get inserted. Here's the insert code:

 $article_countries = "1021,1047,1076,1123"; 

   'article_countries' => array(

Why is the string working where the variable isn't?


I dont think you can build arrays in PHP that way and you end up passing array(0 => '1021,1047,1076,1123') to the param.

Not shure if passing the string is supported:

'article_countries' => $article_countries

If not you could build the array like so:

'article_countries' => array_map('trim', explode(',', $article_countries))
  • Thanks, your comment was helpful for getting me on the right track this AM – kestonh Aug 24 '15 at 14:40

Thanks carlcs, your comment & fresh eyes set me on the right track this morning.

Not real sure why I was wrapping the $article_countries var in another array...

Hopefully this will help somebody else out at 5PM on a Friday...

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.