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 ^^ Commented Feb 17, 2014 at 10:49
  • 1
    do_shortcode() returns only string by the way look Commented Feb 17, 2014 at 11:00
  • do_shortcode() returns only string values. 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. 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. 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.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.