This tutorial helps you to find the POST ID by various ways of various need. During theme or plugin developments we may need to get the post id on demand by some specific parameter like ‘current post’, ‘current page’ etc.
So here i tried to sort out all of theme.
# This function works anywhere outside of loop.
<?php $postid = get_the_ID(); ?>
# If you want get POST ID inside the loop you can use:
<?php the_ID(); ?>
specially uses for getting page id.
$pageName = get_page_by_title( 'About' ); $pageID = $pageName->ID;
$front_page_id = get_option( 'page_on_front' );
$pageID = get_option('page_for_posts');
function get_ID_by_slug($page_slug) { $page = get_page_by_path($page_slug); if ($page) { return $page->ID; } else { return null; } } $postID = get_ID_by_slug('my-post');
<?php $postid = url_to_postid( $url ); ?>
Hope this post helps you lot to find out basic ways to GET POST ID in various requirements. Still if you need any other wasy then feel free to drop a message. We will answer you shortly for your solution.
Thanks.
This post has already been read 10314 times!
What is Lead Capture: In general sense lead capture designates a process or way of…
Introduction Unlimited Modal POPUPS on MouseClick: Everyone knows about popup during site visits and most…
Brief about Pregnancy Calculator : This WordPress Pregnancy Calculator plugin allows users to display an…
Introduction About this Service Plugin: This Visual Composer Service Plugin works as an addon to…
Introduction of Dynamic Query String : This plugin allows user to set dynamic query string…
There is an occasional bug for iPhone and iPad even they are designed as well and…