Shortcodes in custom fields but only when present
-
Hi there
I really need some help with the php for do_shortcode in custom fields.I have a custom field (provided by the Custom Field Creator plugin) that outputs a styled div for customers testimonials on a page template with the following code in:
<?php $testimonial = get_post_meta($post->ID, 'testimonial', true); foreach($testimonial as $testimonial){ echo '<div class="testimonial">'; echo '<p>' . $testimonial['testimonial-text'] . '</p>'; echo '<p class="testimonialname">' . $testimonial['testimonial-name'] . '</p>'; echo '</div>'; } ?>
I’m sure I need to use the `echo do_shortcode(‘[iscorrect]’.$text_to_be_wrapped_in_shortcode.'[/iscorrect]’);
from the codex as I have an [expand][/expand] shortcode that creates a collapsible div when there is a lot of testimonial text. But I only want to invoke the code if the shortcode is present in the div.I have found loads of posts on blogs and entries on the forum here about how to use shortcodes in custom fields and templates, but nothing that I could get to work. Can anyone help me as to how to correctly insert this into my code so that it is only used when the shortcode is present in the custom field value?
The page concerned is at https://www.bridgetglasgow.com/wpress/testimonials.html.
Any help would be very greatly appreciated.
NB I have put a post onto the plugin forum, but had no reply and I feel this is probably quite a generic question anyway.
- The topic ‘Shortcodes in custom fields but only when present’ is closed to new replies.