Skip to content

Instantly share code, notes, and snippets.

@sabrina-zeidan
Created July 29, 2024 16:57
Show Gist options
  • Save sabrina-zeidan/8e012d3c6a203f72cfd5a527ca3640de to your computer and use it in GitHub Desktop.
Save sabrina-zeidan/8e012d3c6a203f72cfd5a527ca3640de to your computer and use it in GitHub Desktop.
Get all post with no thumbnails [WordPress]
// Get posts with no thumbnails
//add_action('wp_head', 'sz_posts_without_thumbs');
function sz_posts_without_thumbs() {
$args = array(
'post_type' => 'post',
'post_status' => 'publish',
'posts_per_page' => -1,
'fields' => 'ids',
'no_found_rows' => true,
'ignore_sticky_posts' => true,
'meta_query' => array(
array(
'key' => '_thumbnail_id',
'compare' => 'NOT EXISTS',
),
),
);
$news_query = new WP_Query($args);
$news_post_ids = $news_query->posts;
echo "<!-- SZCHECK Posts without thumbnails URLs: -->\n";
if (!empty($news_post_ids)) {
foreach ($news_post_ids as $post_id) {
$post_url = get_permalink($post_id);
echo "<a href=\"$post_url\" target='_blank'>$post_url</a><br>";
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment