为什么$post\u id在functions.php中似乎没有价值,但我可以使用它来获取标题($post\u id)?
下面是我想在为什么$post\u id在functions.php中似乎没有价值,但我可以使用它来获取标题($post\u id)?,php,wordpress,Php,Wordpress,下面是我想在add\u action中使用的函数“a”(“内容”,“a”)在functions.php中 function a($content, $post_id){ $x = get_the_title ($post_id); return $content.$x } 当文章加载时,我可以看到标题出现在内容之后 但实际上我想要的是post id的值,所以我尝试 function a($content, $post_id){ return $content.$post_id
add\u action中使用的函数“a”(“内容”,“a”)
在functions.php中
function a($content, $post_id){
$x = get_the_title ($post_id);
return $content.$x
}
当文章加载时,我可以看到标题出现在内容之后
但实际上我想要的是post id的值,所以我尝试
function a($content, $post_id){
return $content.$post_id
}
并且帖子id根本不显示。根据,如果您将空值传递为$id
,则默认情况下WP将获取当前帖子
文章或对象的ID,指定从中获取标题的文章默认情况下,获取当前帖子。
您可以尝试使用
get_the_ID()
而是尝试获取帖子的ID,如果这是您想要的。opps忘记了这是PHP…所以它仍然不能使用?您可以执行var\u dump($post\u id)
并查看它实际包含的内容吗?您可以使用get\u the\u id()获取它代码>-函数存在,只是它是否在循环中工作(我假设它会)@FDL谢谢!和伟大的链接!我稍后再试试。