php版本升级后page页面别名调用出错解决方法

php版本升级到8.3后,page页面别名(slug)调用发生如下错误:

复制代码
Warning: Undefined variable $post in /www/wwwroot/wodepress.com/wp-content/themes/x/functions.php on line 94

Warning: Attempt to read property "ID" on null in /www/wwwroot/wodepress.com/wp-content/themes/x/functions.php on line 94

解决这个问题的方法

1、先在主题文件夹x中找functions.php文件

2、在functions.php文件中找到

复制代码
function the_slug() {
$post_data = get_post($post->ID, ARRAY_A);
$slug = $post_data['post_name'];
return $slug; 
}

3、将上面的代码替换成

复制代码
function the_slug() {
global $post;
$post_data = get_post($post->ID, ARRAY_A);
$slug = $post_data['post_name'];
return $slug; 
}

即可解决这个问题

原文

https://www.jianzhanpress.com/?p=9306

相关推荐
「QT(C++)开发工程师」8 小时前
C++ 11 常用for循环
开发语言·c++
我还记得那天8 小时前
0 初识C++
开发语言·c++
FfHUCisI8 小时前
Go 编译过程全景
开发语言·后端·golang
FfHUCisI8 小时前
Golang 语法分析与 AST:Parser 与 go/ast
开发语言·后端·golang
lemon_sjdk9 小时前
ObjectProperty
java·开发语言·算法
大模型码小白10 小时前
Spring AI Tool 实现自然语言操作 MySQL 数据库详解
服务器·开发语言·数据库·人工智能·python·mysql·spring
hh95010 小时前
Agent Plan x DeepSeek Harness:Agent 供应链安全与第三方插件审计
java·开发语言·安全·agent plan·adg成都社区·adg社区
「QT(C++)开发工程师」10 小时前
C++ std::move 详解
开发语言·c++
matlab代码10 小时前
基于matlab的玉米种子计数设计(GUI界面)【源码58期】
开发语言·matlab