我正在运行Wordpress 4.3.1。这里有两个插件:我和其他一些作者。
我修改了他的代码以捕获在将$post_id
用于全局变量后返回的wp_insert_post
的永久链接,如下所示:
// This is inside one public function of his...
$post_id = wp_insert_post($question_array);
if($post_id){
global $fd_success_post_id;
$fd_success_post_id = get_permalink($post_id);
// The rest of his code does other stuff...not related...
我在我的一个PHP文件中使用了全局变量$fd_success_post_id
,但当我检查它是否设置时,它表示它不是。为什么会发生这种情况?
global $fd_success_post_id;
if(isset($fd_success_post_id)){
echo $fd_success_post_id;
}
else{
echo '$fd_success_post_id not set';
}
有什么想法吗?
答案 0 :(得分:0)
这是因为$fd_success_post_id
未定义。为了使其工作定义为全局,还有
global $fd_success_post_id;
if(isset($fd_success_post_id)){
echo $fd_success_post_id;
}
else{
echo '$fd_success_post_id not set';
}