Title: Adding custom fields documentation (for example ACF fields)
Last modified: January 20, 2023

---

# Adding custom fields documentation (for example ACF fields)

 *  Resolved [Studiobovenkamer](https://wordpress.org/support/users/studiobovenkamer/)
 * (@studiobovenkamer)
 * [3 years, 4 months ago](https://wordpress.org/support/topic/adding-custom-fields-documentation-for-example-acf-fields/)
 * Hi,
 * Thank you for this great plugin!
 * I was wondering if you could shed some light on how you would add custom fields
   to the schema and (especially) how you’d format them. I read the post of [@svitlana41319](https://wordpress.org/support/users/svitlana41319/)
   about [How to add custom fields to the Schema](https://wordpress.org/support/topic/how-to-add-custom-fields-to-the-schema/)
   but I can figure out how to correctly format ACF fields like:
   – Textarea or single
   text line inside a Group field– Repeater field– Relationship field

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

 *  Thread Starter [Studiobovenkamer](https://wordpress.org/support/users/studiobovenkamer/)
 * (@studiobovenkamer)
 * [3 years, 4 months ago](https://wordpress.org/support/topic/adding-custom-fields-documentation-for-example-acf-fields/#post-16399868)
 * Sorry for my typo: …” but I canNOT figure out how to correctly format ACF fields
   like”
 *  Thread Starter [Studiobovenkamer](https://wordpress.org/support/users/studiobovenkamer/)
 * (@studiobovenkamer)
 * [3 years, 4 months ago](https://wordpress.org/support/topic/adding-custom-fields-documentation-for-example-acf-fields/#post-16402774)
 * For other people looking for this information, here’s an example of how to add
   a custom taxonomy to the collection, show it as a facet and show it in your search
   results:
 * **Formatting the data** coming from the custom taxonomy (add this to the `cm_typesense_format_sources_data`
   funtion):
 *     ```wp-block-code
       //Format custom taxonomy 
       $customTaxonomyTerms = get_the_terms($object_id, 'custom_taxonomy');
       $customTaxonomy = [];
       foreach ($customTaxonomyTerms as $customTaxonomyTerm) {
           $customTaxonomy[] = $customTaxonomyTerm->name;
       }
       $formatted_data['custom_taxonomy_name'] = $customTaxonomy;
       ```
   
 * Adding your custom post type to the custom **schema** and showing it as a facet
 *     ```wp-block-code
       ...
       ['name' => 'custom_taxonomy_name', 'type' => 'string[]', 'facet' => true],
       ...
       ```
   
 * Displaying the custom taxonomy in your custom **search results** template:
 *     ```wp-block-code
       <div class="hit-key-custom-taxonomy"><em>Custom taxonomy:</em> data.custom_taxonomy_name</div>
       ```
   
 * That’s it!
 * 
   And another example of formatting a simple ACF textarea and adding it to the
   schema.
 *     ```wp-block-code
       //Format ACF textarea field called 'textarea' inside a ACF group field called 'example_group_field'
   
       $textarea = get_field('example_group_field
       _textarea', $object_id);
       $formatted_data['textarea_name'] = wp_strip_all_tags($textarea);
       ```
   
 *     ```wp-block-code
       ...
       ['name' => 'textarea_name', 'type' => 'string'],
       ...
       ```
   
    -  This reply was modified 3 years, 4 months ago by [Studiobovenkamer](https://wordpress.org/support/users/studiobovenkamer/).
    -  This reply was modified 3 years, 4 months ago by [Studiobovenkamer](https://wordpress.org/support/users/studiobovenkamer/).
 *  Plugin Contributor [Sachyya](https://wordpress.org/support/users/sachyya-sachet/)
 * (@sachyya-sachet)
 * [3 years, 4 months ago](https://wordpress.org/support/topic/adding-custom-fields-documentation-for-example-acf-fields/#post-16402879)
 * Hello [@studiobovenkamer](https://wordpress.org/support/users/studiobovenkamer/),
   glad that you figured it out. Thank you for your feedback and solution.
 * Regarding adding only the ACF fields to the schema and adding data to it. Add
   the following code to your child-theme:
 *     ```wp-block-code
       // Adding the ACF field to schema to be indexed
       function cm_typesense_add_book_schema( $schema, $name ) {
           if ( $name == 'post' ) {
               $schema['fields'][] = [ 'name' => 'acf_textarea', 'type' => 'string' ];
           }
   
   
           return $schema;
       }
       add_filter( 'cm_typesense_schema', 'cm_typesense_add_book_schema', 10, 2 );
   
       // Format the data to be sent to above added ACF field in schema
       function cm_typesense_format_book_data ( $formatted_data, $raw_data, $object_id, $schema_name ) {
           if ( $schema_name == 'post' ) {
               $acf_textarea_value  = get_field( 'text_area', $object_id );
               $formatted_data['acf_textarea'] = $acf_textarea_value;
           }
   
           return $formatted_data;
       }
       add_filter( 'cm_typesense_data_before_entry', 'cm_typesense_format_book_data', 10, 4 );
       ```
   
 * Please make sure to Delete and Re-index your post type after making this change.
 * Hope this helps.
 * Regards,
   Sachet

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

The topic ‘Adding custom fields documentation (for example ACF fields)’ is closed
to new replies.

 * ![](https://ps.w.org/search-with-typesense/assets/icon-256x256.png?rev=3095079)
 * [Search with Typesense](https://wordpress.org/plugins/search-with-typesense/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/search-with-typesense/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/search-with-typesense/)
 * [Active Topics](https://wordpress.org/support/plugin/search-with-typesense/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/search-with-typesense/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/search-with-typesense/reviews/)

 * 3 replies
 * 2 participants
 * Last reply from: [Sachyya](https://wordpress.org/support/users/sachyya-sachet/)
 * Last activity: [3 years, 4 months ago](https://wordpress.org/support/topic/adding-custom-fields-documentation-for-example-acf-fields/#post-16402879)
 * Status: resolved