php - acf 循环中的自定义 slug 函数导致严重错误,define('WP_DEBUG', true); 不显示调试信息
问题描述
我有一个自定义的 slug 函数,我需要在其中获取 URL,将其作为参数传递给函数并“对其进行 slugify”,但它使我的网站崩溃。
下面是代码:
<?php if (have_rows('agenda_section_events')): ?>
<?php while (have_rows('agenda_section_events')) : the_row(); ?>
<?php
function createUrlSlug($urlString) {
$slug=preg_replace('/[^A-Za-z0-9-]+/', '-', $urlString);
return strtolower($slug);
}
$titleToSlug = the_sub_field('agenda_event_title');
$titleSlugged = createUrlSlug($titleToSlug);
?>
<div data-event-box="<?php echo $titleSlugged ?>" class="tc__overlay">
<div style="color: red; display: block !important">$titleToSlug: <?php $titleToSlug ?> $titleSlugged: <?php echo $titleSlugged ?> the_sub_field('agenda_event_title'): <?php the_sub_field('agenda_event_title') ?> createUrlString: <?php echo createUrlSlug('Test string to slug'); ?></div>
<?php endwhile ?>
<?php endif ?>
由于某种原因,这段代码完全使我的网站崩溃 - 我无法调试,因为我无法显示错误日志
它说的是:
本网站出现严重错误。
了解有关 WordPress 故障排除的更多信息。
我试过了:
define('WP_DEBUG', true);
error_reporting(E_ALL);
ini_set('display_errors', 1);
不工作
和
// Enable WP_DEBUG mode
define('WP_DEBUG', true);
// Enable Debug logging to the /wp-content/debug.log file
define('WP_DEBUG_LOG', true);
// Disable display of errors and warnings
define('WP_DEBUG_DISPLAY', false);
@ini_set('display_errors',0);
// Use dev versions of core JS and CSS files (only needed if you are modifying these core files)
define('SCRIPT_DEBUG', true);
也不起作用。
为什么 slugify 代码会破坏我的 wordpress 网站?如何在调试模式下显示错误?
解决方案
推荐阅读
- ios - 如何组合仅样式化分段控件样式的重复代码?
- dialog - 模拟 Vaadin 8 窗口标题的 Vaadin 10 对话框
- c - 如何从 C 中的完整路径(字符串)将文本附加到文件名?
- python - 我希望 Django orm 从 dB 表中找到当前日期和日期时间字段之间的天数差异
- android - Android:使用迭代器解析 JSONArray 键
- php - Facebook Messenger 重复发送用户输入
- php - 检查在 UPDATE 查询中修改了哪些列
- perl - Perl:在多个目录中的多个文件上运行脚本
- php - 在 CakePHP 3 中更新/插入关联表数据
- python - Python 3 整数地址