get_current_user_id()
为以下代码返回 0。我确实尝试了一些堆栈溢出可用的解决方案,但不知何故对我不起作用。我期待解释为什么它返回零以及如何解决?
PS:我从外部 php 页面调用 get_current_user_id() 并包含在内'../wp-blog-header.php'
。
代码:
<?php
require('../wp-blog-header.php');
get_header();
$user_ID = get_current_user_id();
echo $user_ID;
?>