WordPress.org

Ready to get started?Download WordPress

Forums

NextGen gallery shortcode with and id from a custom field (8 posts)

  1. IngridIngrid
    Member
    Posted 3 years ago #

    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]

  2. philipp.schreiber
    Member
    Posted 3 years ago #

    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

  3. IngridIngrid
    Member
    Posted 3 years ago #

    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.

  4. philipp.schreiber
    Member
    Posted 3 years ago #

    Nice :)

  5. swcomm
    Member
    Posted 3 years ago #

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

  6. arthurdent2003
    Member
    Posted 3 years ago #

    thanks

  7. etruxes
    Member
    Posted 3 years ago #

    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!

  8. etruxes
    Member
    Posted 2 years ago #

    nevermind just figured it out. i was missing a php at the beginning, thanks for the snippet philipp, its great!

Topic Closed

This topic has been closed to new replies.

About this Topic