Possible Duplicate:
Shortcode always displaying at the top of the page
我开发了几个插件,通过一个短代码(通过WP\\u查询)获取CPT项目。我遇到的问题是,在调用shortcode之前在WP编辑器中输入的任何内容总是在shortcode数据之后输出。
编辑:
My regular content here
[shortcode]
more content here
页面输出:
shortcode data
My regular content here
more content here
这是我的快捷码查询
$defaults = apply_filters( \'arconix_faq_shortcode_query_args\',
array(
\'post_type\' => \'faq\',
\'showposts\' => \'all\',
\'order\' => \'ASC\',
\'orderby\' => \'title\'
)
);
extract( shortcode_atts( $defaults, $atts ) );
/** Translate \'all\' to -1 for query terms */
if( $showposts == "all" ) $showposts = "-1";
/** Create a new query bsaed on our own arguments */
$faq_query = new WP_Query( array( \'post_type\' => $post_type, \'order\' => $order, \'orderby\' => $orderby, \'posts_per_page\' => $showposts ) );
if( $faq_query->have_posts() ) : while ( $faq_query->have_posts() ) : $faq_query->the_post();
echo \'<div id="post-\' . get_the_ID() .\'" class="arconix-faq-wrap">\';
echo \'<div class="arconix-faq-title">\' . get_the_title() . \'</div>\';
echo \'<div class="arconix-faq-content">\' . get_the_content() . \'</div>\';
echo \'</div>\';
endwhile; endif; wp_reset_postdata();
}
想法?
最合适的回答,由SO网友:Bainternet 整理而成
您的快捷码应该返回其输出,而不是回显,例如:
$defaults = apply_filters( \'arconix_faq_shortcode_query_args\',
array(
\'post_type\' => \'faq\',
\'showposts\' => \'all\',
\'order\' => \'ASC\',
\'orderby\' => \'title\'
)
);
extract( shortcode_atts( $defaults, $atts ) );
/** Translate \'all\' to -1 for query terms */
if( $showposts == "all" ) $showposts = "-1";
/** Create a new query bsaed on our own arguments */
$faq_query = new WP_Query( array( \'post_type\' => $post_type, \'order\' => $order, \'orderby\' => $orderby, \'posts_per_page\' => $showposts ) );
$RetVal = \'\';
if( $faq_query->have_posts() ) : while ( $faq_query->have_posts() ) : $faq_query->the_post();
$RetVal .= \'<div id="post-\' . get_the_ID() .\'" class="arconix-faq-wrap">\';
$RetVal .= \'<div class="arconix-faq-title">\' . get_the_title() . \'</div>\';
$RetVal .= \'<div class="arconix-faq-content">\' . get_the_content() . \'</div>\';
$RetVal .= \'</div>\';
endwhile; endif; wp_reset_postdata();
}
return $RetVal;