• Hi guys
    I recognize that it is not very good with php, so I can not solve this problem:
    I’m using a plugin to manage some galleries on my website
    I would like to use the post_meta to change dinamically the value of a shortcode
    I’m not sure that I explained well 🙂
    anyway this is the code:

    <?php echo do_shortcode(‘[videogallery id=”

    <?php $video = get_post_meta($post->ID, ‘Video’, $single = true); ?>
    <?php if($video !== ”) { ?>
    <?php echo $video; ?>
    <?php } else { echo ”; } ?>

    “]’); ?>

    this is the shortcode:

    <?php echo do_shortcode(‘[videogallery id=”ID”]’); ?>

    I’m trying to replace the “ID” with a post_meta but if I put this code:
    <?php $video = get_post_meta($post->ID, ‘Video’, $single = true); ?>
    <?php if($video !== ”) { ?>
    <?php echo $video; ?>
    <?php } else { echo ”; } ?>
    it seems to crash everything

    Where I’m wrong?
    I appreciate any suggestion 🙂
    Thank you

Viewing 1 replies (of 1 total)
  • you are using php tags in what should be string concatenation; try:

    <?php echo do_shortcode('[videogallery id="'.get_post_meta($post->ID, 'Video', true).'"]'); ?>

    (untested)

    possibly add a conditional statement to the code, to check if the custom field is filled in;
    example:

    <?php $video = get_post_meta($post->ID, 'Video', true); if( $video ) echo do_shortcode('[videogallery id="' . $video . '"]'); ?>
Viewing 1 replies (of 1 total)

The topic ‘PHP question: echo inside echo to execute a shortcode?’ is closed to new replies.