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…
Related Posts:
- How to split up the_title and insert a span tag
- How can i make wordpress blog title clickable and direct to the post itself
- Multilanguage website get the title, on different languages
- Safe way to get the post ID in the_title()
- Replace post title based on conditions
- How to show users search phrase in SEO Title
- Problem with get_the_title in not rendering the way I want
- Replace get_the_title and the_exerpt with custom arrays
- Replacing the title in admin list table
- Is there any difference between the_title() and echo get_the_title()?
- Changing title of a page dynamically from within a plugin
- the_title() and the_permalink() won’t work on AJAX calls
- Remove “Private” + “:” in title does not work
- Get post title with link
- How to get page’s ID if I know the title only?
- the_title(); works in a page template, outside the loop. Why?
- Modifying recent post widget to include icons for post titles
- Replacing the title in admin list table
- How to add hook to the_title() and get_the_title()
- posts order by title second word
- get the_title_attribute by id
- Filter get_the_title to remove certain characters?
- get_title without filter(the_title)
- Is there any difference between get_the_title() and single_post_title()?
- How to change the page title from functions.php
- Long Post Title Misaligning Grid with Featured Image
- get_posts() loop returns the same the_title() for each post
- Can’t get title of latest post
- Including a post title in a twitter link
- How to sanitize post title with commas
- the_title filter returning wrong post type
- How do I hide the current page’s title?
- Custom post type title is set by other custom post type
- WP action/filter to modify title before header output and article output?
- Enter a variable in the ‘category_name’ parameter
- wordpress get gallery images title
- Get url-friendly version of the_title?
- change title separator
- how i can add title to my featured image?
- Access get_the_title() from ‘excerpt_length’ filter
- Blog Title not showing up on main Blog page
- How to output the title of the blogs home page
- Replace text in the Title
- Limit the Title Length on Custom Post Type Archive Page to a Set Number of Characters
- Wrong post title displayed from loop
- get_the_title outputs title until spacing; it does not get full length of title
- post_exists returning 0 if title contain special characters
- How to use get_the_title with text on the ‘alt’ of the_thumbnail array?
- WordPress Image Slider Looping Title Not Working
- Can’t properly set the_title add_filter to show short_URL
- the_title() is not displaying over the_thumbnail
- the_title not working
- single_term_title() running before get_the_title() [closed]
- Get title of post image is attached to
- Can’t get full post title if there a spaces in title
- Title on hovering on the featured image
- How can I remove the first two words and shorten get_the_title()
- get_the_title and get_permalink outside of the Loop
- Shortcode Not Working in Slider When Added To Post Title
- How come I get internal server error even with try catch for get_the_title in functions.php?
- How to place POST TITLE any location inside the posts page
- Print title page in header of a specific page
- Use title of post as argument for query
- WordPress Load Only Page Text
- Change post title if post has specific category
- WordPress title as keywords (tags) with excluded stop words
- Shorten the title length
- Strip $before & $after strings from a page title
- how do I get the title in the post [closed]
- Add title to image post
- How to get changed post title in my custom plug-in which fires when ‘save_post’ is called?
- Can’t Get Parent and Child Categories of Custom Taxonomy to Display
- How to ignore WP_ERROR caused by “get_the_excerpt” method in an AJAX call?
- Filter the title to only affect the_title() template function
- Display Most Recent Post Widget Title On Page
- Trim Titles Only On Some Pages
- Changing Title Tag on Shop Archive Page (current solution reverting to Title of First Product in Loop)
- Modify WordPress Page Title ()
- Display text if title in archive has specific word
- Post title not displaying as recorded in the wp_posts table
- Is it possible to create 2 unique titles for an Events custom post type: Upcoming Events and Past Events?
- Add HTML code before the title of the Tag page
- How to search posts by title with special characters in WP_Query?
- Display title of custom post type dynamically
- Adding Filter | Page Title | Template | Why the_title affecting on menu?
- Customise the_title in admin area
- How to add dynamic content in title and meta description in wordpress theme for homepage, post page, category, tag and pages
- Get title from IDs in a string
- Include category name in page template
- Hide H1 Title using the_title filter
- Get post title of faulty link on 404 error page
- How to get all post titles starting with numbers and symbols?
- Generate page title tag from the content of H1
- Why this Read More Not working in Php?
- Bug with post titles [closed]
- WordPress loop put title into variable
- Show page name in browser
- Title displaying multiple times
- How to store wordpress title in a variable
- echo spesific title get_the_title