# An FAQ, with structured data

> Questions and answers on the page, and the same ones as structured data for search engines.

Source: https://uglydev.com/recipes/an-faq-with-structured-data/
Updated: 20 November 2026

![The FAQ on the site, with one answer open](https://uglydev.com/wp-content/uploads/2026/11/shot-an-faq-with-structured-data-1.webp)

*The FAQ on the site, with one answer open.*

**Fields.** `faq` (Repeater): `question` (Text), `answer` (Rich text).

```php
<?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>';
}
```
