我编写了一个小函数,它使用一个短代码显示一个称为推荐的自定义帖子类型(在我的例子中)。
短代码运行正常。但我注意到了一个主要问题。
调用Shortcode函数后,我的WordPress媒体库不会显示/加载。
只要我删除了Shortcode函数,它就会工作。
我尝试了WP\\U调试以查看是否有错误,但它没有显示任何内容。
此外,检查了php\\u错误日志、apache\\u错误日志,没有什么可以帮助我的。
然后我去了站点健康选项,在那里我看到了
“REST API行为不正确”“REST API未正确处理上下文查询参数”
下面是自定义快捷码函数-
<!-- Shortcode display testimonials-->
<?php
function display_testimonials()
{
?><div class="owl-carousel owl-theme">
<?php
$args = array(
\'post_type\' => \'testimonials\',
\'post_status\' => \'published\',
);
$testimonials = new WP_Query($args);
if($testimonials->have_posts()):while($testimonials->have_posts()):$testimonials->the_post();
?>
<div class="item testimonial_box">
<div class="testimonial_1box">
<span class="testimonial_stars"><?php $stars = get_field(\'stars\'); echo $stars;?></span>
<span class="testimonial_content"><?php the_content();?></span>
<h4 class="testimonial_title"><?php the_title();?></h4>
</div>
<div class="testimonial_2box">
<figure class="figure_testimonial_image">
<img class="testimonial_image" src="<?php the_post_thumbnail();?>
</figure>
</div>
</div>
<?php endwhile; else: ?>
<p>Sorry, there are no posts to display Lavede</p>
<?php endif;?>
</div>
<?php
wp_reset_postdata();
}
function testimonial_shortcode()
{
add_shortcode(\'TestimonialITW\', \'display_testimonials\');
}
add_action(\'init\', \'testimonial_shortcode\');