# Index Table - Indexing child post contents to parent

This is useful, if you don't want to search and return certain posts (or posts from a certain post type), but you want to index the contents along with the parent post.

Ex. Returning Forum topics only as results, but also indexing all the replies to that topic

The codes below only work with the [index table](https://documentation.ajaxsearchpro.com/index-table) engine. After the code is applied, the index table needs to be **re-created** for it to apply.

[What is this, and where do I put this custom code?](/safe-coding-guideline.md)

```php
add_filter('asp_post_content_before_tokenize_clear', 'asp_add_children_to_parent', 10, 2);
	function asp_add_children_to_parent($content, $post) {
	$children_array = get_children( array('post_parent' => $post->ID) );

	if ( !is_wp_error($children_array) )
	foreach ( $children_array as $child ) {
		$content .= " ".$child->post_content;
	}

	return $content;
}
```

### Limiting by post type only

```php
add_filter('asp_post_content_before_tokenize_clear', 'asp_add_children_to_parent', 10, 2);
function asp_add_children_to_parent($content, $post) {
	if ( $post->post_type == 'topic' ) {
		$children_array = get_children( array('post_parent' => $post->ID) );
		if ( !is_wp_error($children_array) )
		foreach ( $children_array as $child ) {
			$content .= " ".$child->post_content;
		}
	}
	return $content;
}
```


---

# 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/post-types/index-table-indexing-child-post-contents-to-parent.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.
