首页 > 解决方案 > 获取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 );
  }
  ?>`````

标签: phpwordpressadvanced-custom-fields

解决方案


推荐阅读