Reply To: Search content of child posts

#10773

Ernest Marcinko
Keymaster

Hi Ana,

1. Search content and child posts

I've looked up the code to maybe somehow append the content of child posts to the parent before the indexing method is invoked. Unfortunately I haven't put any filters there, but we can solve that by making minor modifications:

I.) Make sure to have a back-up of everything on your server in case something goes wrong.
II.) Open up the wp-content\plugins\ajax-search-pro\includes\classes\etc\indextable.class.php file and scroll to line 412 where you should see this:

$content = $the_post->post_content;

and change that to:

$content = apply_filters( 'asp_post_content_before_tokenize_clear', $the_post->post_content, $the_post );

III.) Now that we have a filter to use, put this into the functions.php file in your active theme directory:

This code will get the child posts and append their content to the parent element content before indexing.

IV.) Re-create the index table, and let's hope it works.

2. Filtering by formula

I would recommend using the 'asp_query_args' filter if you can get the post IDs to exclude at that stage – because it's not a post process, and therefore the post count will be more accurate.

Something like this:

Change the line:

$ids = your_formula_to_get_ids_array( $phrase );

to your solution. The $ids variable must be an array of the post IDs you want to exclude, or an empty array().

Best,
Ernest Marcinko

If you like my products, don't forget to rate them on codecanyon :)