Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting the WordPress Post ID of current post

Tags:

php

wordpress

Anyone know how I can get the post ID of the current page?

So, if I'm on a particular post, inside my header.php, I want to be able to get the current post id.

Thanks!

like image 740
dzm Avatar asked Feb 04 '11 00:02

dzm


People also ask

How do I find post ID in WordPress?

You can also find the post ID in the WordPress editor, which you get to by clicking on the post you want. When done this way, the post ID is in the address bar. The URL shown will be exactly the same, and the post ID is again sandwiched between the “post=” and the “&.”

What is Post -> ID?

A post ID is a unique number assigned to each post on a WordPress website. Each page also contains an identifying number, called a page ID. WordPress uses IDs to keep track of every piece of content within the WordPress database.

How can I get slug Post ID?

Bookmark this question. Show activity on this post. $page = get_page_by_path("page-slug", OBJECT, 'page');


1 Answers

Try using this:

$id = get_the_ID(); 
like image 175
Wade Tandy Avatar answered Sep 28 '22 00:09

Wade Tandy