Search code examples
phpwordpressshortcode

How can I use a [Shortcode] in my custom field wordpress


I have a custom wordpress post.php, all posts within a specific category will use this template. In nearly every post there will be scrolling testimonials, to handle this I am using a layer slider.

Within the page I have a custom field of testimonial that is filled with something like [layreslider id="2"] In my php file I have:

<div class="trips-testimonials">
    <?php do_shortcode(get_post_meta($post->ID, 'testimonial', true)); ?>
</div>

This seems to do nothing. If I add echo to the PHP:

<?php echo do_shortcode(get_post_meta($post-ID, 'testimonial', true)); ?>

I get the output of [layreslider id="2"]

Here is a sample page, the blue box under the photo is where the slider should show up. http://www.ct-social.com/ctsdev/aff/capri/

Thank you very much for your help.


Solution

  • looks like you miss the > from post Id so it should read

    <?php do_shortcode(get_post_meta($post->ID, 'testimonial', true)); ?>
    

    Also you may need to call global $post; if outside the loop.