I’ve queried all children of the post, and two records are shown. This is ok because there are 2 images in the gallery, but I can see no field in the database which makes it clear which one is the featured image.

I have joined the wp_postmeta table also, but there is no meta_key which indicates which of the 2 is the featured image.

Note: I do not want to look in the admin panel, I need a programmatic way to determine from the current database setup.

Does anyone know how the system knows which is the featured image in the db?

1 Answer
1

this comes down to a simple one line and there is no need to get all of the children using:

$featured image_id = get_post_meta( $post_id, '_thumbnail_id', true );

Leave a Reply

Your email address will not be published. Required fields are marked *