Home › Forums › Product Support Forums › Ajax Search Pro for WordPress Support › Exclude Pages and Child-Pages from Search Index › Reply To: Exclude Pages and Child-Pages from Search Index
Hi Thomas,
If the pages are in a parent-child relationship directly, then you can exclude them.
For pages there is going to be a checkbox to exclude direct children as well. However this will not exclude them from the index, but only from the individual search instance.
You can however do it programmatically, so before a post is indexed a check is executed to exclude it from the index, something like this:
add_filter(
'asp_index_post',
function ( WP_Post $post ) {
if ( strpos($post->guid, '/path/to/excluded/posts/') !== false ) {
return null;
}
return $post;
}
);
Please note that I did not test this code, but it should be very close to a solution.
Try adding this code via the Code Snippets plugin or to the functions.php file in your theme/child theme directory – make sure to have a full server back-up first for safety. For more details you can check the safe coding guidelines.