Title: NextGen gallery shortcode with and id from a custom field
Last modified: August 19, 2016

---

# NextGen gallery shortcode with and id from a custom field

 *  [IngridIngrid](https://wordpress.org/support/users/ingridingrid/)
 * (@ingridingrid)
 * [15 years, 2 months ago](https://wordpress.org/support/topic/nextgen-plugig/)
 * Can anyone help me with this? .
 * I have the Next Gen slideshow shortcode working when coded into the loop… but
   I need help getting the shortcode to take the slideshow id=X from a custom field
   value.
 * The code just below works, but only with a hardcoded ID (of 3). The IF statement
   checks whether there is a value in the custom field (so if there is no slideshow
   with this post, then nothing is shown).
 * <?php if ( get_post_meta($post->ID, “slideshow”, true) ): ?>
 *  <?php echo do_shortcode(‘[slideshow id=3]’); ?>
 *  <?php endif; ?>
 * What I need is this:
    <?php echo do_shortcode(‘[slideshow id=thecustomfieldvalue]’);?
   >
 * I’ve tried this:
 * <?php echo do_shortcode(‘[slideshow id=<?php echo get_post_meta($post->ID, “nameofyourcustomfield”,
   true); ?>]’); ?>
 * but, it returns [gallery not found]

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

 *  [philipp.schreiber](https://wordpress.org/support/users/philippschreiber/)
 * (@philippschreiber)
 * [15 years, 2 months ago](https://wordpress.org/support/topic/nextgen-plugig/#post-1976376)
 * Hey, you have to do it like this:
 * <?
    $galleryId = get_post_meta($post->ID, “slideshow”, true); if($galleryId) {
   echo do_shortcode(‘[slideshow id=’ . $galleryId . ‘]’); } ?>
 * It’s an untested snippet…
 * Cheers
    Philipp
 *  Thread Starter [IngridIngrid](https://wordpress.org/support/users/ingridingrid/)
 * (@ingridingrid)
 * [15 years, 2 months ago](https://wordpress.org/support/topic/nextgen-plugig/#post-1976380)
 * Hey, Philipp,
 * thank you so much!
 * It worked.
 * This is the first time I’ve posted here. And… I’m so glad I did.
 * Cheers
    Ingrid.
 *  [philipp.schreiber](https://wordpress.org/support/users/philippschreiber/)
 * (@philippschreiber)
 * [15 years, 2 months ago](https://wordpress.org/support/topic/nextgen-plugig/#post-1976383)
 * Nice 🙂
 *  [swcomm](https://wordpress.org/support/users/swcomm/)
 * (@swcomm)
 * [15 years, 2 months ago](https://wordpress.org/support/topic/nextgen-plugig/#post-1976572)
 * Doing exactly the same thing today and this saved me a ton of time. Thanks a 
   bunch.
 *  [arthurdent2003](https://wordpress.org/support/users/arthurdent2003/)
 * (@arthurdent2003)
 * [14 years, 11 months ago](https://wordpress.org/support/topic/nextgen-plugig/#post-1976680)
 * thanks
 *  [etruxes](https://wordpress.org/support/users/etruxes/)
 * (@etruxes)
 * [14 years, 10 months ago](https://wordpress.org/support/topic/nextgen-plugig/#post-1976683)
 * Hi i’m trying to do the same thing only linking a post custom field “projects”
   to a gallery tag, which I have set as a numerical value (ie: 25).
 * For a single instance the shortcode would be this:
    <?php echo do_shortcode(‘[
   nggtags gallery=25]’) ?>
 * I have changed the above to this but nothing is happening:
 * <?
    $galleryId = get_post_meta($post->ID, “project”, true); if($galleryId) { 
   echo do_shortcode(‘[nggtags gallery=’ . $galleryId . ‘]’); } ?>
 * Any help would be really appreciated! thanks!
 *  [etruxes](https://wordpress.org/support/users/etruxes/)
 * (@etruxes)
 * [14 years, 10 months ago](https://wordpress.org/support/topic/nextgen-plugig/#post-1976684)
 * nevermind just figured it out. i was missing a php at the beginning, thanks for
   the snippet philipp, its great!

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

The topic ‘NextGen gallery shortcode with and id from a custom field’ is closed 
to new replies.

## Tags

 * [custom fields](https://wordpress.org/support/topic-tag/custom-fields/)
 * [shortcode](https://wordpress.org/support/topic-tag/shortcode/)

 * 7 replies
 * 5 participants
 * Last reply from: [etruxes](https://wordpress.org/support/users/etruxes/)
 * Last activity: [14 years, 10 months ago](https://wordpress.org/support/topic/nextgen-plugig/#post-1976684)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
