我正在尝试将插件中的短代码添加到我的自定义元数据库中。我已经读过,这不是我要做的事情,但在这种情况下,我确实需要它来工作。客户端可能不会添加视频,但可能会向其中添加图像,或者需要一些东西来确保它仍然可以用于标准内容。
我遇到的问题是,它只输出这样的短代码-[youtube id=“vfGZZJnoJ0U”]
我曾尝试向我的metabox中添加过滤器,但仍然显示了这一点。
这是我的自定义metabox设置:
add_action(\'add_meta_boxes\', \'testimonials_meta_box\');
function testimonials_meta_box() {
add_meta_box(\'testimonials_content_id\', \'Testimonial Image/Video\', \'testimonials_meta_box_cb\', \'kleiser_testimonials\', \'normal\', \'high\');
}
function testimonials_meta_box_cb($post) {
global $post;
wp_nonce_field(\'testimonial_content_nonce\', \'testimonial_content_meta_box_nonce\');
$values = get_post_custom($post->ID);
$left_content = isset($values[\'testimonial_content\']) ? $values[\'testimonial_content\'][0]: \'\';
wp_editor($left_content, \'testimonial-content\');
}
function testimonial_content_save($post_id) {
if(defined(\'DOING_AUTOSAVE\') && DOING_AUTOSAVE) return;
if(!isset($_POST[\'testimonial_content_meta_box_nonce\']) || !wp_verify_nonce($_POST[\'testimonial_content_meta_box_nonce\'], \'testimonial_content_nonce\')) return;
if(!current_user_can(\'edit_pages\')) return;
if(isset($_POST[\'testimonial-content\'])) {
update_post_meta($post_id, \'testimonial_content\', $_POST[\'testimonial-content\']);
}
}
add_action(\'save_post\', \'testimonial_content_save\');
我所做的唯一奇怪的事情是,我将metabox的每个posts值存储在一个数组中,然后执行for循环并输出它们。该代码为:
Edit:
这是我的模板页,其中包含我的所有代码:
<div id=\'hear_what_say_container\'>
<?php $wp_query = new WP_Query(array(\'post_type\' => \'kleiser_testimonials\', \'posts_per_page\'=> -1 )); ?>
<?php if ($wp_query->have_posts()) :
$counter = 0;
$total = $wp_query->post_count;
$testimonialsContentArray = array();
?>
<!-- <div class=\'testimonial\'></div> -->
<div id=\'main_testimonials\'>
<div class=\'testimonial_row\'>
<?php while ($wp_query->have_posts()) : the_post(); ?>
<?php
$media = get_post_meta(get_the_ID(), \'testimonial_content\', true);
?>
<?php array_push($testimonialsContentArray, array(\'id\' => get_the_ID(), \'title\' => get_the_title(), \'content\' => get_the_content(), \'testimonialMedia\' => $media )); ?>
<div class=\'testimonial\' data-id=\'<?php the_ID(); ?>\'>
<div class=\'testimonail_padding\'>
<?php
if ( has_post_thumbnail() ) {
the_post_thumbnail();
}
?>
<div class=\'arrow_indicator\'></div>
</div>
</div>
<?php $counter++; ?>
<?php if($counter % 5 == 0 || $counter == $total ): ?>
</div>
<?php endif; ?>
<?php
foreach($testimonialsContentArray as $testimoninalContent) {
?>
<div class=\'testimonial_details\' data-testimonial=\'<?php echo $testimoninalContent[\'id\']; ?>\'>
<div class=\'detail_left testimonial_content\'>
<div class=\'detail_padding\'>
<?php
echo wpautop($testimoninalContent[\'testimonialMedia\']);
?>
</div>
</div>
<div class=\'detail_right testimonial_content\'>
<div class=\'detail_padding\'>
<h1><?php echo $testimoninalContent[\'title\'] ?></h1>
<?php echo wpautop( $testimoninalContent[\'content\'] ); ?>
</div>
</div>
</div>
<?php
}
?>
<?php //endif; ?>
<?php if($counter % 5 == 0 && $counter < $total ): ?>
<div class=\'testimonial_row\'>
<?php $testimonialsContentArray = array(); ?>
<?php endif; ?>
<?php endwhile; ?>
</div></div>
我挠了好长一段时间的头,不明白为什么我不能找到工作的快捷码。
非常感谢您的帮助
提前感谢
最合适的回答,由SO网友:birgire 整理而成
我注意到你正在使用get_the_content()
, 但它将返回未过滤的内容。
短代码是通过the_content
具有优先级的筛选器11
.
所以如果你想
仅生成短代码,请尝试:
\'content\' => do_shortcode( get_the_content() )
过滤它
the_content
筛选,尝试:
\'content\' => apply_filters( \'the_content\', get_the_content() )
模拟
the_content()
函数,请尝试:
\'content\' => str_replace(\']]>\', \']]>\', apply_filters( \'the_content\', get_the_content() ) )