【问题标题】:Wordpress ACF plugin: trouble getting field when saving postWordpress ACF 插件:保存帖子时无法获取字段
【发布时间】:2015-04-21 10:23:03
【问题描述】:

使用 ACF;我正在制作一个在“draft_to_publish”和“pending_to_publish”上连接到 WP 的插件,这部分工作正常。但是当我尝试获取 ACF 生成的字段时,它们返回为空白,就好像 ACF 生成的字段尚未设置一样。

我的插件的短版如下所示:

function scheduelMailChimp( $post ) {
    // get post data and preb it for mail
    $post_ID        = get_the_ID();
    $content_post   = get_post( $post_ID );
    $content        = $content_post->post_content;
    $postTitle      = get_the_title( $post_ID );

    //log debuginfo til debug.log
    log_me( 
        array( 
               'get field date' => get_field($field_name, $post_id, $format_value)
        )
    );
}

add_action( 'draft_to_publish', 'scheduelMailChimp', 10, 1 );
add_action( 'pending_to_publish', 'scheduelMailChimp', 10, 1 );

上面的代码输出为空。如果我尝试输出由 WP 而不是 ACF 生成的东西,一切都会像魅力一样。

欢迎所有和任何聪明的想法:)

【问题讨论】:

    标签: wordpress advanced-custom-fields


    【解决方案1】:

    万一其他人也在寻找相同的答案:在进行了大量的 Google 搜索之后,ACF 似乎在 draft_to_publish 被触发时还没有保存数据。所以我尝试使用“save_post”,它就像一个魅力。

    【讨论】:

      猜你喜欢
      • 2019-07-19
      • 2015-11-21
      • 2021-12-08
      • 2021-08-11
      • 1970-01-01
      • 1970-01-01
      • 2020-04-15
      • 2018-08-21
      • 1970-01-01
      相关资源
      最近更新 更多