> For the complete documentation index, see [llms.txt](https://knowledgebase.ajaxsearchpro.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://knowledgebase.ajaxsearchpro.com/miscellaneous/post-types/index-table-indexing-child-post-contents-to-parent.md).

# 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;
}
```
