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?

  • because the shortcode returns array you can't echo it, foreach() loop can help ^^ – JMau Feb 17 '14 at 10:49
  • 1
    do_shortcode() returns only string by the way look – JMau Feb 17 '14 at 11:00
  • do_shortcode() returns only string values. – Abhik Feb 17 '14 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 Feb 17 '14 at 11:20
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).

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

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.