Get post/page title from ID

If you have only ID of a post and you want only the title of that post, then using get_post_field will be best way to do this, I guess.

The syntax of this function:

get_post_field( $field, $post_id, $context );

So code, that will solve your problem looks like that:

$title = get_post_field( 'post_title', $POST_ID );
// most probably you want to display the title, so you can ignore last param

And addressing your code snippets… First method should work, if the post exists and it’s published or current user can see it.

Second method can’t work. It makes no sense.

Third and fourth methods can’t work also. These functions don’t take post_ID as param, so such use of them doesn’t make much sense…

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)