ZHAO Xudong
ZHAO Xudong

Reputation: 1411

how to obtain the post id in wordpress templates

i know in wordpress loop

the_ID();

will output the post id, if i want to set $var = the post id; what should i do?

Upvotes: 0

Views: 716

Answers (1)

Damien Pirsy
Damien Pirsy

Reputation: 25435

Instead of the_ID(), which echoes its result, use the function get_the_ID(), which returns the ID and you can assing it to a variable to be used in your php script.

$postid = get_the_ID();
/* do here what you need with $postid.. */

FYI, there's a nice official repository of WP APIs, the CODEX

Upvotes: 1

Related Questions