I have a site with hundreds of posts, each with an image URL stored in a custom field called fulllimage
. These URLs are either images on the Instagram CDN or thumbnails on the Youtube CDN. Every now and then, some of these URLs expire or people are deleting the corresponding content directly from these platforms.
I need a way, to filter out the affected posts in the WordPress admin panel to be able to bulk trash/delete them. I already created custom filters before using restrict_manage_posts
but afaik, this method is just creating a query to check a certain field or taxonomy value.
I did something like this in the past to filter based on a network
dropdown.
add_action('pre_get_posts',[$this, 'filter_posts_by_network']);
public function filter_posts_by_network($query) {
if ( is_admin() && $query->is_main_query() ) {
$scr = get_current_screen();
if ($scr->base === 'edit' && in_array($scr->post_type, $this->cpts, true)) {
if (isset($_GET['network']) && $_GET['network'] != 'all') {
$query->set('meta_query', array( array(
'key' => 'network',
'value' => sanitize_text_field($_GET['network'])
) ) );
}
}
}
}
My guess would be, to loop over all the entries and check wether the URL in the fullimage
field is returning a 404 or not and then, somehow tell the list to update. But i need a hint on how to approach this or if there is even a better way to do it.