php - 获取NULL的返回值
问题描述
嘿伙计们,我似乎在以下代码中为 'mainEntity' => array() 返回了一个 NULL 值。尝试了一切有人有任何想法吗?认为我的变量没有正确传递给函数。
<?php
$schema = array(
'@context' => "https://schema.org",
'@type' => "FAQPage",
'mainEntity' => array()
);
// Get Advanced Custom Fields Values
if ( have_rows('faq') ) {
while ( have_rows('faq') ) : the_row();
if ( have_rows('faq_section') ) {
while ( have_rows('faq_section') ) : the_row();
$questions = array(
'@type' => 'Question',
'name' => get_sub_field('faq_question'),
'acceptedAnswer' => array(
'@type' => "Answer",
'text' => get_sub_field('faq_answer')
)
);
array_push($schema['mainEntity'], $questions);
endwhile;
}
endwhile;
function faq_schema ($schema) {
global $schema;
echo '<!-- FAQ Structured data --><script type="application/ld+json">'. json_encode($schema) .'</script>';
}
add_action( 'wp_footer', 'faq_schema', 100 );
}
?>`````
解决方案
推荐阅读
- java - 如何删除字符串中的引号?
- vaadin - 表单关闭后,Vaadin Select 下拉值继续显示?
- flutter - 尝试使用选项卡栏切换数据,但只有第一个选项卡正在工作并且在第二个选项卡上得到空响应
- typescript - 在 Angular 项目中切换分支时节点模块会丢失
- python - 测试时使用 DjangoRestAPIKey
- javascript - JWT Token 不以 Bearer String 开头,并且在发送时以 Bearer 开头的公理
- flutter - 页面打开时开始计数的简单计时器 [Flutter]
- laravel-8 - 即使定义了路由,Laravel 也不支持 POST 方法
- reactjs - 如何在具有特定值的输入上方放置一个 div?
- java - 如何在父片段处理 onBackPressed