Created
July 29, 2024 16:57
-
-
Save sabrina-zeidan/8e012d3c6a203f72cfd5a527ca3640de to your computer and use it in GitHub Desktop.
Get all post with no thumbnails [WordPress]
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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