[wp-trac] [WordPress Trac] #23983: Add filter to get_post_thumbnail_id to override default thumbnail use
WordPress Trac
noreply at wordpress.org
Sun Apr 7 20:48:44 UTC 2013
#23983: Add filter to get_post_thumbnail_id to override default thumbnail use
-----------------------------+-------------------------
Reporter: Jesper800 | Type: enhancement
Status: new | Priority: normal
Milestone: Awaiting Review | Component: Media
Version: | Severity: normal
Keywords: 2nd-opinion |
-----------------------------+-------------------------
The current function for getting the post thumbnail ID, used in among
others `get_the_post_thumbnail`, is as follows:
{{{
function get_post_thumbnail_id( $post_id = null ) {
$post_id = ( null === $post_id ) ? get_the_ID() : $post_id;
return get_post_meta( $post_id, '_thumbnail_id', true );
}
}}}
In my opinion, this needs a filter, so the user can override this by the
attachment of his choosing, such as an Advanced Custom Fields image
attached to the post.
Something like:
{{{
function get_post_thumbnail_id( $post_id = null ) {
$post_id = ( null === $post_id ) ? get_the_ID() : $post_id;
return apply_filters( 'post_thumbnail_id', get_post_meta(
$post_id, '_thumbnail_id', true ), $post_id );
}
}}}
I know you can hook into the `get_{$meta_type}_metadata` filter, but
getting the post thumbnail ID should still be possible by using
get_post_meta, the other thumbnail should just be used for displaying.
--
Ticket URL: <http://core.trac.wordpress.org/ticket/23983>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list