我创建了自己的简码以显示自定义帖子类型的数据。 我可以在页面上显示具有自定义值的不同车型。但是我的CPT还支持编辑器(WPBakery Page Builder),管理员可以为每辆汽车添加/自定义额外的内容。 (其他信息)。
我的问题: 我想在自定义字段下面添加/显示编辑器的内容(=> the_content)。但是,一旦我输出“ the_content”,它就会出现在每种汽车的页面顶部。我可以使用“ get_the_content”将数据显示在正确的位置(“。$ content。”),但是它不会包含任何格式,也不会显示图片,而是输出整个img标签+信息。
有什么办法可以解决这个问题?
提前谢谢!
输出the_content()
使用get_the_content()输出
<?php
if(!defined('ABSPATH')){
exit;
}
add_shortcode('fahrzeuge', 'display_fahrzeuge');
function display_fahrzeuge($atts, $content = null) {
$output = '';
$args = array(
'post_type' => 'fahrzeuge',
'post_status' => 'publish',
'tax_query' => array(
array(
'taxonomy' => 'Fahrzeugtypen',
'field' => 'slug',
'terms' => 'kommandofahrzeuge')));
$output.= '';
$kommandofahrzeuge = new WP_Query( $args );
if( $kommandofahrzeuge->have_posts() ) :
while( $kommandofahrzeuge->have_posts() ) :
$kommandofahrzeuge->the_post();
$post_id = get_the_ID();
$taktischeBezeichnung = esc_html(get_post_meta($post_id,'ff_ried_fahrzeuge_taktischeBezeichnung', true));
$featured_img_url = get_the_post_thumbnail_url($post_id,'full');
$output.='
<div>'.$taktischeBezeichnung.'</div>
<img class="fahrzeugeFeaturedImage" src='.$featured_img_url.'></img>
<div>'.$content.'</div>
';
endwhile;
wp_reset_postdata();
else :
esc_html_e( 'Keine Fahrzeuge gefunden', 'text-domain' );
endif;
echo $output;
}
?>
答案 0 :(得分:0)
解决方案: 将此函数插入functions.php
function get_the_content_with_formatting ($more_link_text = '(more...)', $stripteaser = 0, $more_file = '') {
$content = get_the_content($more_link_text, $stripteaser, $more_file);
$content = apply_filters('the_content', $content);
$content = str_replace(']]>', ']]>', $content);
return $content;
}
显示格式化的内容:
$content = get_the_content_with_formatting();
echo $content;
来源:http://www.web-templates.nu/2008/08/31/get_the_content-with-formatting/index.html