WordPress.org

Support

Support » Plugins and Hacks » NextGen gallery shortcode with and id from a custom field

NextGen gallery shortcode with and id from a custom field

  • 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)
  • 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

    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.

    Nice 🙂

    Doing exactly the same thing today and this saved me a ton of time. Thanks a bunch.

    thanks

    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!

    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.