🛍 Spring Sale DISCOUNT! + 2x Benefits for FREE

Click Here!

How to Use ACF Repeater Fields to Automate FAQ Schema

In this knowledgebase article, we’re going to walk you through how to use ACF Repeater Fields to Automate FAQ Schema.

1 Install Rank Math Plugin

First, you need to Install the Rank Math plugin.

Rank Math Plugin

2 Install Advanced Custom Field

Once you have installed Rank Math, then install the Advanced Custom Field. Please ensure that the ACF module is enabled from WordPress Dashboard → Rank Math SEO → Dashboard.

Advanced Custom Fields PRO

3 Create ACF Repeater Field

Create a new ACF Repeater Field. To do so, navigate to Custom Field → Field Groups. Click on Add New as shown below:

Field Groups

4 Create New FAQ Fields

Create a new field as FAQ Fields and click on Add Field as shown below:

Add New Field Group

Fill in all the details and select the Field Type as Repeater.

Field Type- Repeater

5 Create Field for FAQ Question

Create a new field for FAQ Question in the Repeater field as shown below:

FAQ Questions

6 Create Field for FAQ Answer

Similarly create a new field for FAQ Answer in the Repeater field.

FAQ Answer

7 Create a Post and Fill the FAQ Fields

Add a new Post and fill the FAQs using the newly created fields.

Fill the FAQ in Post

8 Add the Code in rank-math.php File

Navigate to WordPress Dashboard → Appearance → Theme File Editor.

Navigate to Theme File Editor

In case, if it is a block theme you should navigate to WordPress Dashboard → Tools → Theme File Editor.

Theme File Editor in Block Theme

Now, select rank-math.php in the theme files. If you’re automating the FAQ Schema for your posts, add the below code snippet to the rank-math.php file.

add_filter( 'rank_math/json_ld', function( $data, $jsonld ) {
if( ! have_rows('faq-acf-repeater') ) {
return $data;
}
$data['faqs'] = [
'@type' => 'FAQPage',
];
while( have_rows('faq-acf-repeater') ) {
the_row();
$data['faqs']['mainEntity'][] = [
'@type' => 'Question',
'name' => esc_attr( get_sub_field('faq_question') ),
'acceptedAnswer' => [
'@type' => 'Answer',
'text' => esc_attr( get_sub_field('faq_answer') ),
],
];
}
return $data;
}, 10, 2 );

If you’re automating the FAQ Schema for your categories, add the below code snippet to the rank-math.php file.

add_filter( 'rank_math/json_ld', function( $data, $jsonld ) {	
    if(is_category()) {
		$queried_object = get_queried_object_id( );
		if( ! have_rows('faq-acf-repeater', "category_".$queried_object) ) {
		return $data;
	    }
        $data['faqs'] = [
            '@type' => 'FAQPage',
        ];
        while( have_rows('faq-acf-repeater', "category_".$queried_object) ) {
            the_row();
            $data['faqs']['mainEntity'][] = [
                '@type' => 'Question',
                'name' => esc_attr( get_sub_field('faq_question', "category_".$queried_object) ),
                'acceptedAnswer' => [
                '@type' => 'Answer',
                'text' => esc_attr( get_sub_field('faq_answer', "category_".$queried_objectt) ),
                ],
            ];
        }
    }
	return $data;
}, 10, 2 );

Once done, edit the filter as explained below.

  • Change the faq-acf-repeater to the field created in step 3 at line2.
  • Change faq_question to the field created in step 5 at line 12.
  • Change faq_answer to the field created in step 6 at line 15.

Finally, click the Update File button.

If you still have any questions about how to use ACF repeater fields to automate FAQ Schema – you’re always more than welcome to contact our dedicated support team. They are available 24/7, 365 days a year…

Still not using Rank Math?

Setup takes less than 5 minutes including the import from your old SEO Plugin!

Learn more about the PRO Version

Still need help?

?

Submit Your Question

Please give us the details, our support team will get back to you.

Open Ticket

Related Articles