【发布时间】:2019-12-03 04:33:54
【问题描述】:
要求:在每个发布/更新帖子上,我们需要来自的所有标签 发布并在上面做一些功能。
案例 1: 创建帖子,添加标签并立即发布 === 完美运行 ===
案例 2: 更新旧帖子并点击更新按钮。 === 完美运行 ===
案例 3: 创建帖子,添加标签并将其保存到草稿并关闭..再次打开同一个帖子并点击发布而不更改任何内容 === 失败 === 帖子结果中没有任何内容.. 未找到标签,但帖子中已有标签, 但是如果我们改变一些东西或者只是删除并添加相同的标签,那么它就可以工作。
我希望第 3 种情况能够正常工作。如何在发布时获取草稿帖子的标签。
下面是我的代码
// This is hook which calls automatically on publish the post
add_action( 'publish_post', array($this, 'post_published_notification'), 10, 2 );
// The function calls on publish the post
public static function post_published_notification( $ID, $post )
{
$request_body = file_get_contents('php://input');
PostPublishNotification::saveDataInNotificationTable($ID,$request_body);
}
// We neen the tags here..
public static function saveDataInNotificationTable($ID,$request_body)
{
$post_data = json_decode($request_body);
// Here is nothing when I publish the drafted post. otherwise it works when I publish/update the new/old post
var_dump($post_data);
exit;
$tags = $post_data->tags;
if(isset($tags) && is_array($tags) && count($tags) > 0)
{
// SOME CODE
}
}
【问题讨论】:
-
请停止滥用报价格式。这是为了当您实际引用某人或某事时,不是让您的文字“看起来更丰富多彩”......