I need to set fake thumbnails to all posts which have yet no a thumbnail. I use the code from the link core.trac.wordpress.org/ticket/40547#comment:1
But I can't check if a post already has a thumbnail inside of the first function mentioned.
If I try the has_post_thumbnail()
that is
function wp40547_filter_post_thumbnail_id( $null, $post_id, $meta_key, $single ) {
if ( '_thumbnail_id' !== $meta_key ) {
return $null;
}
if( has_post_thumbnail( $post_id ) == false) {
$attachment_id = 'my_fake_id';
}
return $attachment_id;
}
add_filter( 'get_post_metadata', 'wp40547_filter_post_thumbnail_id', 10, 4 );
I receive the 502 error, as I can understand because the has_post_thumbnail()
calls the get_post_thumbnail_id()
which in turns calls the get_post_meta()
and the get_post_metadata()
so we call ourselves
How to check in the case?