Quantcast
Channel: WordPress › Support » Forum: Hacks - Recent Topics
Viewing all articles
Browse latest Browse all 8245

RUbuntix on "Current Page Title or ID"

$
0
0

Hello!

Maybe this is a simple question, but I found so many different
answers and none worked for me, so I do have to ask it here:

how do I get the ID of the current page in php?

I tried:
$currId = get_the_ID();

but this works only for pages with NO posts (otherwise
it seems to give me an post-id even without the loop
-> could this be true?)

or
wp_title( '|', true, 'right' )

this seems to be empty.

or

global $post;
$post->ID

This returns the ID of a post (if there is at least one).

I also found this one:

$page_object = get_queried_object();
 $page_id     = get_queried_object_id();

This one always returns 0.

So: which function returns the current page (not the posts) ID
outside the loop?

Thank you for help!


Viewing all articles
Browse latest Browse all 8245

Trending Articles