Hi,
my code:
<?php
$schema = array(
'@context' => "https://schema.org",
'@type' => "FAQPage",
'mainEntity' => array()
);
global $schema;
if (have_rows('pytania_i_odpowiedzi')) {
while (have_rows('pytania_i_odpowiedzi')) : the_row();
$questions = array(
'@type' => 'Question',
'name' => get_sub_field('pytanie'),
'acceptedAnswer' => array(
'@type' => "Answer",
'text' => get_sub_field('odpowiedz')
)
);
array_push($schema['mainEntity'], $questions);
endwhile;
function generate_faq_schema($schema)
{
global $schema;
echo '<script type="application/ld+json">' . json_encode($schema) . '</script>';
}
add_action('wp_footer', 'generate_faq_schema', 100);
}
?>
I am getting an error:
array_push() expects parameter 1 to be array, null given
How to fix it?
I have a solution
global $schema;
$schema = array(
'@context' => "https://schema.org",
'@type' => "FAQPage",
'mainEntity' => array()
);
You must be logged in to reply to this topic.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.