Suggest Fields is returning string and not array

I am working with the ‘suggest’ field and it is returning a string and not an array of ids.

The documentation says that the return value should be an array. However, like I said I am getting back a comma list of ids as a string. Is this a error in the docs? I want to make sure before I move forward with development.

Thanks.

Hey David,

It looks like the docs are incorrect. I checked the code and I believe it’s returning a JSON encoded array of values. You should be able to do this to get an array in php…

$my_array = json_decode( $settings->my_values );

Let me know if that helps. I’ll get the docs updated.

Justin

Thanks Justin.

Hey Justin, it is not working.
I am using the ‘suggest’ to find tags from a custom taxonomy. That works fine and what is returned is a list of ids separated by a comma. It is not in JSON format…just a string (string ‘9, 7, 4’) and when I apply json_decode() I am getting a null return.
The string value I am getting back is fine as a comma list as I can explode() it, but I want to make sure it is not a bug or other changes will be made to make my code break.
Thanks

Hey David,

Sorry about that! At first glance it looked like a JSON encoded array but it is in fact just a comma separated string of the values. I’ve updated the docs to reflect that.

Justin

That fine Justin, my biggest concern was to clarify the correct output and not build around the wrong output. Thanks for the quick response.

You’re welcome, David!