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

相关推荐
小短腿的代码世界几秒前
从KB到字节:Qt行情数据压缩与传输优化的全链路透视——LZ4、Snappy与自定义二进制协议的极限压榨
开发语言·qt
灵机一物16 分钟前
灵机一物AI原生电商小程序、PC端(已上线)-【技术深度解析】Bun 6 天 AI 重写 96 万行代码:从 Zig 迁移 Rust 全流程与行业影响
开发语言·人工智能·rust
Nontee17 分钟前
Java 后端面试题目全集
java·开发语言·面试
lsx20240621 分钟前
CSS 选择器
开发语言
Chase_______39 分钟前
【Java杂项】0.1 + 0.2 为什么不等于 0.3?IEEE 754 与 BigDecimal 精度避坑
java·开发语言·python
ch.ju40 分钟前
Java Programming Chapter 4——Static part
java·开发语言
geovindu41 分钟前
python: Monitor Pattern
开发语言·python·设计模式·监控模式
之歆43 分钟前
DAY_11JavaScript BOM与DOM深度解析:底层原理与工程实践(上)
开发语言·前端·javascript·ecmascript
会编程的土豆1 小时前
Go ini 配置加载:`ini.MapTo` 详细解析
开发语言·数据库·golang
ChoSeitaku1 小时前
04.数组
java·开发语言·数据结构