# 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="/files/cltPkXzkWr6gGpGTm29k" alt="" width="188"><figcaption></figcaption></figure>
* Use the custom code below. [Where do I put the custom code?](/safe-coding-guideline.md)
* 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="/files/COxXTkVMGfJS1RK5XTrB" 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
);
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://knowledgebase.ajaxsearchpro.com/miscellaneous/tutorials/indexing-shortcodes-within-custom-field-contents.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
