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('~�*([0-9a-f]+);~ei', 'chr(hexdec("\1"))', $faq_topic);
$faq_tag = preg_replace('~�*([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.
get_the_content()
does not have thethe_content
filters applied to it, which is wheredo_shortcode()
is hooked in. Those filters are only applied inthe_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 thethe_title
filters.If you want the whole
the_content
filter stack applied, do:If you only want shortcodes applied, do: