
Fields. faq (Repeater): question (Text), answer (Rich text).
<?php $items = ugly_rows( 'faq' ); ?>
<?php foreach ( $items as $item ) : ?>
<details>
<summary><?php $item->show( 'question' ); ?></summary>
<?php $item->show( 'answer' ); ?>
</details>
<?php endforeach; ?>
<?php
if ( $items ) {
$schema = array(
'@context' => 'https://schema.org',
'@type' => 'FAQPage',
'mainEntity' => array_map(
static fn ( $item ) => array(
'@type' => 'Question',
'name' => wp_strip_all_tags( $item->get( 'question' ) ),
'acceptedAnswer' => array(
'@type' => 'Answer',
'text' => wp_kses_post( $item->get( 'answer' ) ),
),
),
$items
),
);
echo '<script type="application/ld+json">' . wp_json_encode( $schema ) . '</script>';
}