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.

link|improve this question

77% accept rate
feedback

1 Answer

up vote 5 down vote accepted

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() )
link|improve this answer
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. – Norcross Feb 23 '11 at 3:43
Some example code. – Mark Jaquith Feb 23 '11 at 5:17
That was it. I also realized I wasn't actually calling the 2nd shortcode correctly. – Norcross Feb 23 '11 at 8:16
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.