Home › Forums › Product Support Forums › Ajax Search Pro for WordPress Support › Ignore unlinked Attachments › Reply To: Ignore unlinked Attachments
March 5, 2019 at 4:35 pm
#21403
Keymaster
Hi!
While there is no feature/option for that on the back-end, it should be possible by using a custom code. Try adding this custom code to the functions.php in your theme/child theme directory. Before editing, please make sure to have a full site back-up just in case!
add_filter('asp_results', 'asp_results_remove_unlinked_attachments');
function asp_results_remove_unlinked_attachments($results) {
foreach ($results as $k => &$r) {
if ( $r->content_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;
}
I hope this helps!