[wp-trac] [WordPress Trac] #30970: setup_postdata should be able to accept a Post ID, currently requires full WP Post object
WordPress Trac
noreply at wordpress.org
Sat Jan 10 02:05:03 UTC 2015
#30970: setup_postdata should be able to accept a Post ID, currently requires full
WP Post object
-------------------------------+------------------------------
Reporter: sc0ttkclark | Owner:
Type: enhancement | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Posts, Post Types | Version: 1.5
Severity: normal | Resolution:
Keywords: | Focuses:
-------------------------------+------------------------------
Comment (by sc0ttkclark):
I have found only one gotcha, which would be that get_post() will return
the current global post object, if $post is empty.
This can be alleviated by:
{{{
public function setup_postdata( $post ) {
global $id, $authordata, $currentday, $currentmonth,
$page, $pages, $multipage, $more, $numpages;
if ( empty( $post ) ) {
return false;
} elseif ( ! is_object( $post ) ) {
$post = get_post( $post );
if ( ! $post ) {
return false;
}
}
$id = (int) $post->ID;
}}}
--
Ticket URL: <https://core.trac.wordpress.org/ticket/30970#comment:2>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list