wordpress - Wordpress、save_post、post_status 并不是数据库中的内容
问题描述
add_action("save_post", [$this, "save"]);
function save($postId)
{
$post = get_post($post_id);
echo $post->post_status; // its "inherit" instead of "publish" !
echo $post->post_status; // its "revision" instead of "draft" !
}
然后在数据库中有“ publish
”,我得到get_post($post_id)->post_status
=> ' inherit
' !
或者在数据库中有“ draft
”,我得到get_post($post_id)->post_status
=> ' revision
' !
为什么?我需要根据 post_status 做一些操作,我不能那样做
解决方案
推荐阅读
- python - 在 python 中检查 .txt 文件的上下文:True, False
- java - 为什么 CopyOnWriteArrayList 的迭代器在增强型 for 循环中允许 remove(),而它的迭代器不支持 remove() 操作?
- symfony - 如何使用 Shivas/versioning-bundle 格式化版本号?
- .net-core - ServiceStack 和 Kestrel:使用 .Map 函数根据路径(中间件)路由到 ServiceStack 实例?
- asynchronous - 来自 REST 响应的 UWP 设置图像
- php - Firefox 不遵守 RFC6265 关于处理 cookie 的路径属性
- redis - 如何使用 cloudbuild.yaml 在 GCP 上配置 redis?
- c# - 如何统一地向单个布娃娃肢体添加力量?
- azure-devops - 在 Azure DevOps 中如何以增量方式发出拉取请求
- git - git commit 后的 Visual Studio 社区运行命令