Title: GP Blocks / structured data / faq
Last modified: July 18, 2022

---

# GP Blocks / structured data / faq

 *  Resolved [Jan](https://wordpress.org/support/users/locke85/)
 * (@locke85)
 * [3 years, 10 months ago](https://wordpress.org/support/topic/gp-blocks-structured-data-faq/)
 * Hi David,
 * I’d like to embed structured data into a FAQ section built with [two GB containers and headline blocks](https://webgefaehrte.de/wp-content/uploads/2022/07/Bildschirmfoto-2022-07-18-um-23.12.57-scaled.jpg).
 * An online generator tool like this would provide me with the JSON-LD to add to
   an HTML block.
 * This issue is that this JSON-LD includes both question and answer into the same
   snippet. For my template, however, I need two code snippets, one for the question
   and one for the answer.
 * When I look at the html of the Yoast FAQ block they seem to use and ID in order
   to a questions to the relevant answer (see [screenshot](https://webgefaehrte.de/wp-content/uploads/2022/07/Bildschirmfoto-2022-07-18-um-23.12.57-scaled.jpg)).
 * How would you go about splitting the following:
 *     ```
       <script type="application/ld+json">
       {
         "@context": "https://schema.org",
         "@type": "FAQPage",
         "mainEntity": [
           {
             "@type": "Question",
             "name": "This is the Question.",
             "acceptedAnswer": {
               "@type": "Answer",
               "text": "Here comes the Answer."
             }
           }
         ]
       }
       </script>
       ```
   
 * Any advise would be much appreciated.
 * Best,
    Jan
 * The page I need help with: _[[log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Fgp-blocks-structured-data-faq%2F%3Foutput_format%3Dmd&locale=en_US)
   to see the link]_

Viewing 14 replies - 1 through 14 (of 14 total)

 *  Plugin Support [David](https://wordpress.org/support/users/diggeddy/)
 * (@diggeddy)
 * [3 years, 10 months ago](https://wordpress.org/support/topic/gp-blocks-structured-data-faq/#post-15845291)
 * Hi there,
 * I am not sure i fully understand what the issue is.
    If its because you have:
 * 1 x JSON-LD snippet for the FAQ
    2 x Container Blocks to display then Question
   and the Answer
 * Then this should not be an issue.
    The search engine reads the JSON-LD. The human
   reads the displayed HTML. Yes google will check that the Question and Answers
   in the JSON-lD are visible to the reader but to my knowledge there is no coded
   connection between the two.
 * Let me know what i am missing
 *  Thread Starter [Jan](https://wordpress.org/support/users/locke85/)
 * (@locke85)
 * [3 years, 10 months ago](https://wordpress.org/support/topic/gp-blocks-structured-data-faq/#post-15850493)
 * Hi David,
 * yes, you got this right. There are two container blocks, one is supposed to contain
   the questions, the other holds the related answer.
 * I understand that could place the script including question and answer for Google
   in one place and the same information for the user visible in a different format.
 * The problem with that is that I’ll need to maintain both answers and questions
   in two places.
 * Alternatively, I created [this structure](https://webgefaehrte.de/wp-content/uploads/2022/07/Bildschirmfoto-2022-07-22-um-17.17.57-scaled.jpg)
   that splits the script into two and places relevant parts into the different 
   container. Then I added the `name` and `text` attributes as an HTML tag to the
   subsequent text blocks inside the same container.
 * Will this direction lead us anywhere meaningful 😉
 * Any thoughts are much appreciated.
 * Best,
    Jan
 *  Plugin Support [David](https://wordpress.org/support/users/diggeddy/)
 * (@diggeddy)
 * [3 years, 10 months ago](https://wordpress.org/support/topic/gp-blocks-structured-data-faq/#post-15850584)
 * I am no expert on the JSON-LD schema, but i do not believe you can split the 
   JSON script into two.
 * How many Questions and Answers are there to be on each page ?
 *  Thread Starter [Jan](https://wordpress.org/support/users/locke85/)
 * (@locke85)
 * [3 years, 10 months ago](https://wordpress.org/support/topic/gp-blocks-structured-data-faq/#post-15850632)
 * Hi David,
 * only one question an one answer on each page.
 * The challenge comes with the total number of 100+ pages ;-/
 * Best,
    Jan
 *  Plugin Support [David](https://wordpress.org/support/users/diggeddy/)
 * (@diggeddy)
 * [3 years, 10 months ago](https://wordpress.org/support/topic/gp-blocks-structured-data-faq/#post-15855965)
 * Have you thought about using Custom Fields to store the Question and Answer.
   
   You can then:
 * 1. Use the Headline Block Dynamic Data -> Content Source -> Post Meta -> Field
   name to display the Question, and again the Answer
 * 2. Then use a PHP Snippet to print your Schema in the `<head>` of your site. 
   eg.
 *     ```
       add_action( 'wp_head', 'db_print_faq_json', 99 );
   
       function db_print_faq_json() {
           // Check if its a single post
           if ( is_single() ) {
       	// Get Custom field: question and answer
               global $post;
               $question = get_post_meta( $post->ID, 'question', true );
               $answer = get_post_meta( $post->ID, 'answer', true );
               // if both question and answer are present print JSON
               if ( $question && $answer ) {
                   printf('
                   <script type="application/ld+json">
                   {
                     "@context": "https://schema.org",
                     "@type": "FAQPage",
                     "mainEntity": [
                       {
                         "@type": "Question",
                         "name": "%1$s",
                         "acceptedAnswer": {
                           "@type": "Answer",
                           "text": "%2$s"
                         }
                       }
                     ]
                   }
                   </script>',
                   $question,
                   $answer
                   );
               }
           }
       }
       ```
   
 * Notes:
 * a. `if ( is_single() ) {` this condition first checks if your on a single post.
   Change this condition if you’re using a specific post type for your FAQs
 * b. these two lines is where we grab the custom fields:
 *     ```
       $question = get_post_meta( $post->ID, 'question', true );
        $answer = get_post_meta( $post->ID, 'answer', true );
       ```
   
 * You need to upodate the `question` in: `$post->ID, 'question', true` to match
   your field names, and the same for the `answer`
 * This way you only have to add the Question and Answer to your custom field, and
   the rest can be done automatically.
 *  Thread Starter [Jan](https://wordpress.org/support/users/locke85/)
 * (@locke85)
 * [3 years, 10 months ago](https://wordpress.org/support/topic/gp-blocks-structured-data-faq/#post-15860879)
 * Hi David,
 * this sounds like a great approach. Many thanks for laying this out.
 * I’ll add another Custom Field to the CPT and then let you know how it went.
 * In the meantime, let’s assume this works for the FAQ related JSON. I’m planning
   to apply the same approach to a how-to JSON also. In this case would you recommend
   me extending the same CPT with another set of Custom Fields or rather create 
   a new CPT for how-tos (and why)?
 * FYI: Currently, I’m using a [Custom Field](https://webgefaehrte.de/wp-content/uploads/2022/07/Bildschirmfoto-2022-07-26-um-18.26.03-scaled.jpg)
   to determine the Type of “JSON” that is required.
 * Best,
    Jan
 *  Plugin Support [David](https://wordpress.org/support/users/diggeddy/)
 * (@diggeddy)
 * [3 years, 10 months ago](https://wordpress.org/support/topic/gp-blocks-structured-data-faq/#post-15862973)
 * Thats hard for me to answer, as one multipurpose CPT vs many specific CPTs will
   come down to how you intend to use them.
 * My initial stance would be to create a new CPT.
    It keeps things simple, you 
   don’t have to do anything fancy for standard things, like archive pages of just
   How To’s or search just that post type, or making changes to it single template.
 * I would change my stance if there was a need to related the content or create
   a hierarchical structure eg. Parent ( FAQ ) -> Child ( How To ).
 *  Thread Starter [Jan](https://wordpress.org/support/users/locke85/)
 * (@locke85)
 * [3 years, 9 months ago](https://wordpress.org/support/topic/gp-blocks-structured-data-faq/#post-15931754)
 * Hi David,
 * many thanks for your answer regarding multipurpose CPTs. Happy to follow your
   advise and keep things simple in the first FAQ version.
 * Meanwhile, I also managed to update your PHP snippet. The CPT is `wg_seo_chat`
   and the custom field for the question is `wg_chat_options_question`. In the current
   design the answer does not have a custom field but uses the `post content` standard
   field.
 *     ```
       add_action( 'wp_head', 'db_print_faq_json', 99 );
   
       function db_print_faq_json() {
           // Check if its a single post
           if ( is_wg_seo_chat() ) {
       	// Get Custom field: question and answer
               global $post;
               $question = get_post_meta( $wg_chat_options_question->ID, 'question', true );
               $answer = get_post_meta( $post->ID, 'answer', true );
               // if both question and answer are present print JSON
               if ( $question && $answer ) {
                   printf('
                   <script type="application/ld+json">
                   {
                     "@context": "https://schema.org",
                     "@type": "FAQPage",
                     "mainEntity": [
                       {
                         "@type": "Question",
                         "name": "%1$s",
                         "acceptedAnswer": {
                           "@type": "Answer",
                           "text": "%2$s"
                         }
                       }
                     ]
                   }
                   </script>',
                   $question,
                   $answer
                   );
               }
           }
       }
       ```
   
 * Is that how you would add it to the function.php?
 * Thanks,
    Jan
    -  This reply was modified 3 years, 9 months ago by [Jan](https://wordpress.org/support/users/locke85/).
 *  Plugin Support [David](https://wordpress.org/support/users/diggeddy/)
 * (@diggeddy)
 * [3 years, 9 months ago](https://wordpress.org/support/topic/gp-blocks-structured-data-faq/#post-15940986)
 * Hi Jan
 * Couple of things:
 * 1. The template condition ie.
 * `if ( is_wg_seo_chat() ) {`
 * Unless you have a custom function called `is_wg_seo_chat()` you should change
   that to:
 * `if ( is_single() && is_post_type('wg_seo_chat') ){`
 * 2. Getting the question from post meta:
 * if `wg_chat_options_question` is the custom field ( meta key name ). Then this:
 * `$question = get_post_meta( $wg_chat_options_question->ID, 'question', true );`
 * should be:
 * `$question = get_post_meta( $post->ID, 'wg_chat_options_question', true );`
 * More info on the `get_post_meta` function and its args here:
 * [https://developer.wordpress.org/reference/functions/get_post_meta/](https://developer.wordpress.org/reference/functions/get_post_meta/)
    -  This reply was modified 3 years, 9 months ago by [David](https://wordpress.org/support/users/diggeddy/).
 *  Thread Starter [Jan](https://wordpress.org/support/users/locke85/)
 * (@locke85)
 * [3 years, 9 months ago](https://wordpress.org/support/topic/gp-blocks-structured-data-faq/#post-15957669)
 * Hi David,
 * many thanks for providing this helpful push.
 * To keep thinks simple, I have created two custom fields, one for the question
   and one for the answer ;-). The PHP now looks as follows:
 *     ```
       // Support Chat - FAQ header inject
   
       add_action( 'wp_head', 'db_print_faq_json', 99 );
       function db_print_faq_json() {
           // Check if its a single post
           if ( is_single() && is_post_type('wg_seo_chat') ){
         // Get Custom field: question and answer
               global $post;
               $question = get_post_meta( $post->ID, 'wg_chat_options_question', true );
               $answer = get_post_meta( $post->ID, 'wg_chat_options_answer', true );
               // if both question and answer are present print JSON
               if ( $question && $answer ) {
                   printf('
                   <script type="application/ld+json">
                   {
                     "@context": "https://schema.org",
                     "@type": "FAQPage",
                     "mainEntity": [
                       {
                         "@type": "Question",
                         "name": "%1$s",
                         "acceptedAnswer": {
                           "@type": "Answer",
                           "text": "%2$s"
                         }
                       }
                     ]
                   }
                   </script>',
                   $question,
                   $answer
                   );
               }
           }
       }
       ```
   
 * Unfortunately the desired page is not loading when include the PHP into the function
   php. The WP debug log shows the [the following error](https://webgefaehrte.de/wp-content/uploads/2022/08/Screen-Shot-2022-08-28-at-10.56.19-PM-scaled.jpg).
 * Please let me know how to correct the error in line 114 `if ( is_single() && 
   is_post_type('wg_seo_chat') ){`
 * Many thanks in advance.
 * Best,
    Jan
 * PS: [Link](https://b3qn4j.myraidbox.de/seo-hilfe-chat/newsletter-nutzen/) to 
   relevant page
 *  Plugin Support [David](https://wordpress.org/support/users/diggeddy/)
 * (@diggeddy)
 * [3 years, 9 months ago](https://wordpress.org/support/topic/gp-blocks-structured-data-faq/#post-15958714)
 * Doh, change:
 * `if ( is_single() && is_post_type('wg_seo_chat') ){`
 * to:
 * `if ( is_singular( 'wg_seo_chat' ) ) {`
 *  Thread Starter [Jan](https://wordpress.org/support/users/locke85/)
 * (@locke85)
 * [3 years, 9 months ago](https://wordpress.org/support/topic/gp-blocks-structured-data-faq/#post-15972049)
 * Hi David,
 * many thanks for your quick reply.
 * This fix did the trick. You made my day!
 * As you can see from the [screenshot](https://webgefaehrte.de/wp-content/uploads/2022/09/Screen-Shot-2022-09-01-at-11.17.43-PM-scaled.jpg),
   the text from both question and answer fall in place nicely.
 * Best,
    Jan
 *  Plugin Support [David](https://wordpress.org/support/users/diggeddy/)
 * (@diggeddy)
 * [3 years, 9 months ago](https://wordpress.org/support/topic/gp-blocks-structured-data-faq/#post-15973122)
 * Glad to be of help!
 *  [Eldar](https://wordpress.org/support/users/guglastican/)
 * (@guglastican)
 * [3 years, 7 months ago](https://wordpress.org/support/topic/gp-blocks-structured-data-faq/#post-16180352)
 * I really do not understand this tutorial 🙁
 * I want FAQ on my post with generate blocks or without a plugin. I fix the schema
   FAQ with a custom field, but I want to show the FAQ in my posts.

Viewing 14 replies - 1 through 14 (of 14 total)

The topic ‘GP Blocks / structured data / faq’ is closed to new replies.

 * ![](https://ps.w.org/generateblocks/assets/icon.svg?rev=3239461)
 * [GenerateBlocks](https://wordpress.org/plugins/generateblocks/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/generateblocks/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/generateblocks/)
 * [Active Topics](https://wordpress.org/support/plugin/generateblocks/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/generateblocks/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/generateblocks/reviews/)

 * 14 replies
 * 3 participants
 * Last reply from: [Eldar](https://wordpress.org/support/users/guglastican/)
 * Last activity: [3 years, 7 months ago](https://wordpress.org/support/topic/gp-blocks-structured-data-faq/#post-16180352)
 * Status: resolved