Title: Complex do_shortcode statements
Last modified: August 20, 2016

---

# Complex do_shortcode statements

 *  Resolved [johnsalomon](https://wordpress.org/support/users/johnsalomon/)
 * (@johnsalomon)
 * [14 years, 11 months ago](https://wordpress.org/support/topic/complex-do_shortcode-statements/)
 * Hi there,
 * I am trying to construct a do_shortcode statement in a PHP code widget, using
   a custom field. The idea is to get a shortcode evaluated inside a widget.
 * The shortcode I’m trying to create is (this is an example)
 * _[flickrgallery setid=”72157626892022672″]_
 * I want to use a custom value (called _per\_post\_widget\_content_) on a per-post
   basis that lets me enter 72157626892022672 in a field.
 * I figure I have to have statements that echo ‘[flickrgallery setid=”‘, then get_post_meta
   for the custom field value (this part works), then echo ‘”]’
 * The do_shortcode statement I have so far is
 * <?php global $post do_shortcode(echo ‘[flickrgallery setid=”‘; echo get_post_meta(
   $post->ID, ‘per_post_widget_content’, true); echo ‘”]’;); ?>
 * This does not work.
 * I’ve tried variations on this, but I can’t get the syntax right – can someone
   give me a pointer on what I’m doing wrong?

Viewing 3 replies - 1 through 3 (of 3 total)

 *  [Michael](https://wordpress.org/support/users/alchymyth/)
 * (@alchymyth)
 * [14 years, 11 months ago](https://wordpress.org/support/topic/complex-do_shortcode-statements/#post-2163371)
 * basics:
    [http://php.net/manual/en/function.echo.php](http://php.net/manual/en/function.echo.php)
   [http://php.net/manual/en/function.return.php](http://php.net/manual/en/function.return.php)
   [http://php.net/manual/en/language.operators.string.php](http://php.net/manual/en/language.operators.string.php)
 * `do_shortcode()` needs a string to work on;
    you cannot use echo in this situation
   within the brackets, rather use string concatenation; (not to confuse with the
   fact that you need to use `echo do_shortcode()` because `do_shortcode()` does
   return the result)
 * example:
 *     ```
       <?php global $post; echo do_shortcode('[flickrgallery setid="' . get_post_meta($post->ID, 'per_post_widget_content', true) . '"]'); ?>
       ```
   
 *  Thread Starter [johnsalomon](https://wordpress.org/support/users/johnsalomon/)
 * (@johnsalomon)
 * [14 years, 11 months ago](https://wordpress.org/support/topic/complex-do_shortcode-statements/#post-2163374)
 * I’ll give that a shot, thank you. Still learning 🙂
 * (That gives me an error
 * _Invalid argument supplied for foreach()_
 * but I think that’s related to the theme I’m using. Thanks!
 *  Thread Starter [johnsalomon](https://wordpress.org/support/users/johnsalomon/)
 * (@johnsalomon)
 * [14 years, 11 months ago](https://wordpress.org/support/topic/complex-do_shortcode-statements/#post-2163500)
 * This works, brilliant, thank you so much.

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Complex do_shortcode statements’ is closed to new replies.

## Tags

 * [complex](https://wordpress.org/support/topic-tag/complex/)
 * [do_shortcode](https://wordpress.org/support/topic-tag/do_shortcode/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 3 replies
 * 2 participants
 * Last reply from: [johnsalomon](https://wordpress.org/support/users/johnsalomon/)
 * Last activity: [14 years, 11 months ago](https://wordpress.org/support/topic/complex-do_shortcode-statements/#post-2163500)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
