I'm trying to get several values from a shortcode. I tried several things without success.

The shortcode looks like this:

[myshortcode metakey="<field_key:key1, title:Title 1><field_key:key2, title:Title 2><field_key:key3, title:Title 3> ]

How would I get the field_key values? So in this case key1, key2 and key3?

  • Can you explain what you are trying to accomplish? And why do you need such a complicated single attribute? Exactly what things did you try? Also, post the code that processes the shortcode.
    – s_ha_dum
    Oct 25, 2013 at 14:50
  • @s_ha_dum Well it's a bit to complex to explain. But let's say I want to have a list of all posts from a category that is filled in in the shortcode. And above that a custom title. Let's say this was my shortcode: [myshortcode category="<cat:Dogs, title: My dogs><cat:Cats, title: My Cats>"] Then I would somehow know how to get the values out of the shortcode.
    – Trekdrop
    Oct 25, 2013 at 14:59

1 Answer 1


Don't try to shove everything into a single attribute, or a single shortcode even. The string parsing you have to do will get more and more complicated. Try this:

function myshortcode_cb( $atts ) {
  $atts = shortcode_atts( 
      'cat' => '',
      'title' => ''
  //   var_dump($atts); // debug
  return "{$atts['cat']} :: {$atts['title']}";

With this:

[myshortcode cat="key1" title="Title 1" /]

And create a shortcode for each case.

  • That's not the answer to this question, tho.
    – marvinpoo
    Nov 27, 2019 at 9:33

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.