• Resolved Eliot Akira

    (@miyarakira)


    I’d like to use a shortcode as a parameter to pass to another shortcode:

    [google_map address="[content field='address']"]

    However, this outputs a blank map plus this string: “]

    I’ve looked in both shortcodes to see if do_shortcode() on the parameter would solve it, but no luck. Would anybody have an idea how to achieve this?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator bcworkz

    (@bcworkz)

    The nested square brackets mess up the regexp used to find shortcodes in content. You could combine the shortcode callbacks so the ‘google_map’ address parameter is run through the former ‘content’ callback code before being used in the ‘google_map’ code.

    If you need to also supply address parameters that are not processed by ‘content’ code, you could allow for two different parameters, one passed through former ‘content’ code, the other not.

    Another possibility is using a different syntax for nested shortcodes, such as curly brackets {} to get around confusing the shortcode regexp. Add some code to replace any curly brackets found with square before running the parameter through do_shortcode(). Such content would look like this:
    [google_map address="{content field='address'}"]

    Thread Starter Eliot Akira

    (@miyarakira)

    Thank you for the answer! In fact, just today I ran into the same problem again, but with a different first shortcode. It’s because I’m using my own ‘content’ shortcode to get custom fields into the post, and naturally I sometimes want to use that field as a parameter to pass to another shortcode.

    I looked for a solution elsewhere and was told, “It’s not possible” – but you showed me several possibilities. The thing is, I don’t want to alter the first shortcode (usually written by others) to make it possible.

    The 3rd option looks good, and I remember seeing this workaround before. I am using another shortcode to do query loops, so I think I’ll include a function to replace curly brackets like this:

    [loop field="address"][google_map address="{FIELD}"][/loop]

    Not as elegant as I’d hoped, but it’s the simplest solution to implement without altering the google map or any another shortcode which uses the parameter.

    Once again, thank you for pointing me in the right direction.

    Thread Starter Eliot Akira

    (@miyarakira)

    I confirmed that the curly bracket solution works. Great!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Shortcode as parameter to another shortcode’ is closed to new replies.