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

Reply To: Ignore unlinked Attachments

#21403
Ernest MarcinkoErnest Marcinko
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!