How do I get a custom post by its ID? I want to display a single post from custom post using its ID. I tried 'post_type' => 'homepage', 'post_id' => '717' but it didnt work.

Thanks

1 Answer
1

You simply don’t need to specify a post_type when calling get_post(). The ID for any sort of post is unique among the whole DB-posts table. So if you’re calling a post with ID = 17

$id = 17;
$post = get_post( $id );

then you’ll simply get this single post.

Note, according the Codex, when using get_post

You must pass a variable containing an integer (e.g. $id). A literal integer (e.g. get_post(7)) will cause a fatal error (Only variables can be passed for reference or Cannot pass parameter 1 by reference).

Leave a Reply

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