# Indexing Shortcodes within custom field contents

By default shortcodes are not executed in custom field contents before indexing to avoid some known issues. In rare cases - such as using an ACF field with a Tablepress or any other shortcode it is neccessary.

### Steps to get a shortcode indexed in a custom field

* Configure the [index table engine](https://documentation.ajaxsearchpro.com/index-table) as you need it, but don't index yet (Don't click Create New index button, if you did, just reload the page)
* Make sure that the custom field, which contains the shortcode(s) is also selected. In this example I'm using "field\_name" as the field.<br>

  <figure><img src="https://1744076133-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M9rmHbZfTKVQ7YzbIZL%2Fuploads%2FFuAzeGIDQhqjSZsZCiLQ%2Fimage.png?alt=media&#x26;token=6bd9577e-c58c-4e45-8136-5eb72d1ded05" alt="" width="188"><figcaption></figcaption></figure>
* Use the custom code below. [Where do I put the custom code?](https://knowledgebase.ajaxsearchpro.com/safe-coding-guideline)
* Make sure to change the **$field\_name** variable to the custom field, which contains the shortcode(s)
* Now create the index<br>

  <figure><img src="https://1744076133-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M9rmHbZfTKVQ7YzbIZL%2Fuploads%2FnDGf07nlU0sVrk2pDHBx%2Fimage.png?alt=media&#x26;token=fa9800f2-7916-4661-adda-9f4719a193fb" alt="" width="188"><figcaption></figcaption></figure>
* Make sure that the index table engine [is enabled](https://documentation.ajaxsearchpro.com/index-table/enabling-index-table-engine) on the search instance settings as well

The custom code snippet to index custom field with shortcodes:

```php
add_filter(
	'asp_post_custom_field_before_tokenize',
	function ( $values, $the_post, $field ) {
		$field_name = 'field_name';

		// Do not change anything below
		$new_values = array();
		if ( $field === $field_name ) {
			foreach( $values as $value ) {
				$new_values[] = do_shortcode($value);
			}
		}

		return $new_values;
	},
	10,
	3
);
```
