Home › Forums › Product Support Forums › Ajax Search Pro for WordPress Support › Ignore unlinked Attachments › Reply To: Ignore unlinked Attachments
March 5, 2019 at 4:50 pm
#21405
Keymaster
Hi,
Yep, that should filter the live results. I have made a correction to the code right after I posted, you might still got the original post. Can you please verify, that this is the code:
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;
}
You don’t have to clear the cache, this should work effective immediately.