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 engine. After the code is applied, the index table needs to be re-created for it to apply.
1
add_filter('asp_post_content_before_tokenize_clear', 'asp_add_children_to_parent', 10, 2);
2
function asp_add_children_to_parent($content, $post) {
3
$children_array = get_children( array('post_parent' => $post->ID) );
4
5
if ( !is_wp_error($children_array) )
6
foreach ( $children_array as $child ) {
7
$content .= " ".$child->post_content;
8
}
9
10
return $content;
11
}
Copied!

Limiting by post type only

1
add_filter('asp_post_content_before_tokenize_clear', 'asp_add_children_to_parent', 10, 2);
2
function asp_add_children_to_parent($content, $post) {
3
if ( $post->post_type == 'topic' ) {
4
$children_array = get_children( array('post_parent' => $post->ID) );
5
if ( !is_wp_error($children_array) )
6
foreach ( $children_array as $child ) {
7
$content .= " ".$child->post_content;
8
}
9
}
10
return $content;
11
}
Copied!
Last modified 1mo ago