php - WordPress v5.0.3:无法检查图库短代码
问题描述
我对 WordPress 开发比较陌生。最近,我安装了 WordPress 5.0.3,从那时起就遇到了一个奇怪的问题。我要做的就是检查帖子是否包含使用has_shortcode
函数的画廊并将画廊作为标签传递给它。
这是代码的样子,代码是自定义page.php
文件的摘录。
<div class="container">
<?php
$wpb_all_query = new WP_Query(array('post_type' => 'post', 'post_status' => 'publish', 'posts_per_page' => -1));?>
<?php if ($wpb_all_query->have_posts()): ?>
<?php while ($wpb_all_query->have_posts()): $wpb_all_query->the_post();?>
<div class="row">
<div class="col-12">
<div class="d-flex justify-content-center">
<?php esc_html(the_title());?>: <?php
if (has_shortcode(the_content(), 'gallery')):
echo "TRUE";
else:
echo "FALSE";
endif;?>
</div>
</div>
</div>
<?php endwhile;?>
<?php wp_reset_postdata();?>
<?php endif;?>
</div>
has_shortcode
即使帖子中嵌入了画廊,该函数也始终返回 false。
不确定,这种检查帖子是否包含画廊的方式在当前版本中是否仍然有效。
我知道代码的格式很差,但由于时间限制,我不想在这里花时间格式化它。
解决方案
推荐阅读
- sql-server - CTE 基于输入创建递归动态行和列
- python - 如何在sqlalchemy中选择列存在
- java - 从 java 应用程序发送时没有在服务器中获取正确的 json
- python - Plotly-Dash:如何打印条形图的 hoverData?
- javascript - 如何在 jquery 中创建一个按钮,其 href 属性等于 ajax 响应
- php - 使用 php mailer 邮件从 localhost xamp 成功发送,但未能在生产 Windows 托管中发送
- angular - 如何在不重新加载整个站点的情况下更新子组件
- c++ - C ++:即使使用“this”关键字,参数声明也会隐藏类成员
- react-native - React-native 使 List-FlatList 与 Texts 可滚动
- android - 如何以编程方式获取 ADB 路径?