Home › Forums › Product Support Forums › Ajax Search Pro for WordPress Support › Search can't find certain documents and parent posts › Reply To: Search can't find certain documents and parent posts
May 20, 2020 at 1:23 pm
#27457
Keymaster
Hi,
I have found a custom code in your theme functions.php file, which removes unlinked attachments from the search results – this is causing the problem:
/*FILTER AJAX SEARCH PRO RESULTS SO UNLINKED ATTACHMENTS DONT SHOW UP*/
add_filter('asp_results', 'asp_results_remove_unlinked_attachments');
function asp_results_remove_unlinked_attachments($results) {
foreach ($results as $k=>&$r) {
if ( isset($r->post_type) && $r->post_type == 'attachment' ) {
$parent_id = wp_get_post_parent_id( $r->id );
if ( is_wp_error($parent_id) || empty($parent_id) ) {
// Remove the post from the results list
unset($results[$k]);
}
}
}
return $results;
}
The missing results does not have parent posts, only simple media elements, and this custom code is removing them. Removing this custom code should resolve the issues.