2

I've been racking my brain on this. Here is a shortcode loop I've created to display a specific post type:

 function faq_shortcode($atts, $content = NULL) { extract(shortcode_atts(array( 'faq_topic' => '', 'faq_tag' => '', 'faq_id' => '', 'limit' => '10', ), $atts)); $faq_topic = preg_replace('~&#x0*([0-9a-f]+);~ei', 'chr(hexdec("\\1"))', $faq_topic); $faq_tag = preg_replace('~&#x0*([0-9a-f]+);~ei', 'chr(hexdec("\\1"))', $faq_tag); $faqs = new WP_Query(array( 'p' => ''.$faq_id.'', 'faq-topic' => ''.$faq_topic.'', 'faq-tags' => ''.$faq_tag.'', 'post_type' => 'question', 'posts_per_page' => ''.$limit.'', 'orderby' => 'menu_order', 'order' => 'ASC' )); $displayfaq= '<div class="faq_list">'; while ($faqs->have_posts()) : $faqs->the_post(); $displayfaq .= '<div class="single_faq">'; $displayfaq .= '<h3 class="faq_question">'.get_the_title().'</h3>'; $displayfaq .= '<p class="faq_answer">'.get_the_content().'</p>'; $displayfaq .= '</div>'; endwhile; wp_reset_query(); $displayfaq .= '</div>'; return $displayfaq; } add_shortcode('faq','faq_shortcode'); 

within one of those loops there is a post that has a shortcode being used

function emailbot_ssc($atts, $content = null) { extract( shortcode_atts( array( 'address' => '', ), $atts ) ); ob_start(); echo '<a href="mailto:'.antispambot($atts['address']).'" title="email us" target="_blank" rel="nofollow">'.$atts['address'].'</a>'; $email_ssc = ob_get_clean(); return $email_ssc; } add_shortcode("email", "emailbot_ssc"); 

the FAQ loop (code item #1) isn't parsing the shortcode. It just displays it raw.

0

1 Answer 1

5

get_the_content() does not have the the_content filters applied to it, which is where do_shortcode() is hooked in. Those filters are only applied in the_content(). Those two functions are not simply get/echo versions of each other. get_the_content() is lower level.

This is an anomaly in the API, and is that way for historical reasons. For instance, get_the_title() applies the the_title filters.

If you want the whole the_content filter stack applied, do:

apply_filters( 'the_content', get_the_content() ) 

If you only want shortcodes applied, do:

do_shortcode( get_the_content() ) 
3
  • That's what I assumed, and doing that doesn't seem to make a difference. If I put it outside that loop it doesn't chance anything, and if I put the it in the loop itself the content in the shortcode disappears completely. Commented Feb 23, 2011 at 3:43
  • Some example code. Commented Feb 23, 2011 at 5:17
  • That was it. I also realized I wasn't actually calling the 2nd shortcode correctly. Commented Feb 23, 2011 at 8:16

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.