Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/272.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 创建post后,用于REST的ACF字段为空_Php_Rest_Action_Advanced Custom Fields - Fatal编程技术网

Php 创建post后,用于REST的ACF字段为空

Php 创建post后,用于REST的ACF字段为空,php,rest,action,advanced-custom-fields,Php,Rest,Action,Advanced Custom Fields,每次发布帖子时,我都会发送推送通知。所有工作正常,但ACF字段为空。相反,当我重新保存post数据时,数据会正确通过 基本工作流程 用户发布帖子 触发操作以发送推送通知 ACF字段的有效负载为空(标题、摘录、休息字段为ok) 我已经读了好几篇文章,但是在创建文章之后,无法实现将ACF字段交付给rest 我所尝试的: 优先级为100,以确保帖子已保存,然后稍后获取信息 add_action( "save_post", ["Yaguarete

每次发布帖子时,我都会发送推送通知。所有工作正常,但ACF字段为空。相反,当我重新保存post数据时,数据会正确通过

基本工作流程

  • 用户发布帖子
  • 触发操作以发送推送通知
  • ACF字段的有效负载为空(标题、摘录、休息字段为ok)
我已经读了好几篇文章,但是在创建文章之后,无法实现将ACF字段交付给rest

我所尝试的:

优先级为100,以确保帖子已保存,然后稍后获取信息

add_action(
      "save_post",
      ["YaguaretePluginApiBlog", "postPushNotification"],
      100,
      3
    );
尝试使用转换后状态,结果相同

add_action(
       "transition_post_status",
       ["YaguaretePluginApiBlog", "postPushNotification"],
       99,
       3
     );

所有这些都会触发,没有问题,但当涉及到获取ACF字段时,什么都不起作用

还尝试了默认的acf/save_post,但不幸的是,与其他操作相比,此操作甚至没有启动

add_action("acf/save_post", [
      "YaguaretePluginApiBlog",
      "postPushNotification",
    ]);
这就是我试图得到的acf字段

尝试使用ACF中的_字段函数

$data[notificationType] = the_field(
       "yaguarete_push_notification",
       $_post->ID
     );
试图使用post_meta检索字段信息

$data[notificationType] = get_post_meta($post["id"])[
       "yaguarete_push_notification"
     ][0]
试图从ACF使用get_字段

get_field("yaguarete_push_notification", $post["id"], false)
似乎什么都不管用,有经验的人能指出我做错了什么吗


提前感谢

有人闯入同一个问题,我最终使用了以下钩子“”

经过几次测试,其中包括仅在post发布时触发某些操作,这就成功了:

add_action(
      "rest_after_insert_post",
      ["YaguaretePluginApiBlog", "postPushNotification"],
      100,
      3
    );
仅在发布新帖子时发送推送


Hook已经保存了所有元数据,包括ACF字段,这是我的原始问题,没有从这个自定义字段中检索值

你检查过ACF/save\u post Hook吗?我猜在默认的save post功能中,ACF数据尚未更新,因此您描述的尝试失败。您好@mynd,感谢您的回复,是的,我尝试过,出于某种原因,不会触发。用它更新了帖子
add_action(
      "rest_after_insert_post",
      ["YaguaretePluginApiBlog", "postPushNotification"],
      100,
      3
    );
function postPushNotification($post, $request, $creating)
  {
    $postOriginal = $post;
    $post = [get_post($post->ID)];
    $post = YaguaretePluginApiBlog::formatPosts($post)[0];

    //only send push notification when
    if (
      $postOriginal->post_type == "post" &&
      $postOriginal->post_status == "publish" &&
      $postOriginal->post_modified == $postOriginal->post_date
    ) {