0

I have made a shortcode [get_clients] which is supposed to return an array of all the clients when called via do_shortcode('[get_clients]'). But all it returns is a string 'Array' only. Why?

4
  • because the shortcode returns array you can't echo it, foreach() loop can help ^^
    – JMau
    Commented Feb 17, 2014 at 10:49
  • 1
    do_shortcode() returns only string by the way look
    – JMau
    Commented Feb 17, 2014 at 11:00
  • do_shortcode() returns only string values.
    – Abhik
    Commented Feb 17, 2014 at 11:19
  • Shortcodes are intended to be used to print something on the screen. This is the reason why they return always a string: only a string can be printed. If you trying to use a shortcode to return an array, you are _doing_it_wrong. Add in question the relevant code you are using, and probably someone can suggest you a different solution.
    – gmazzap
    Commented Feb 17, 2014 at 11:20

1 Answer 1

1

This function returns a string. So you should join the elements of the array to make a string.

From the Codex:

Function Reference/do shortcode

Return Values

(string)

Content with shortcodes replaced by the output from the shortcode's handler(s).

2
  • 1
    I can serialize an array before returning and then unserialize it.
    – arxoft
    Commented Feb 17, 2014 at 11:44
  • Please read @G. M.'s comment as well: "Shortcodes are intended to be used to print something on the screen." Commented Feb 17, 2014 at 11:54

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.