This website uses cookies to personalize your experience. By using this website you agree to our cookie policy.

Reply To: Ignore unlinked Attachments

#21513
Ernest MarcinkoErnest Marcinko
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;
}