开发者

how to obtain the post id in wordpress templates

开发者 https://www.devze.com 2023-02-11 14:44 出处:网络
i know in wordpress loop the_ID(); w开发者_StackOverflowill output the post id, ifi want to set $var = the post id;

i know in wordpress loop

the_ID();

w开发者_StackOverflowill output the post id, if i want to set $var = the post id; what should i do?


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号