Home › Forums › Product Support Forums › Ajax Search Pro for WordPress Support › Ignore unlinked Attachments › Reply To: Ignore unlinked Attachments
March 8, 2019 at 3:27 pm
#21513
Keymaster
Hi,
I think you might have an older version of the plugin, I am not sure. In that case, this modification should do the trick:
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;
}