【发布时间】:2018-11-09 12:22:20
【问题描述】:
根据 WordPress codex save_post_{$post->post_type} 应该传递三个参数:
do_action( "save_post_{$post->post_type}", int $post_ID, WP_Post $post, bool $update )
这是我的代码:
add_action( 'save_post_guide', array($this, 'saveGuideMeta') );
function saveGuideMeta(int $post_ID, WP_Post $post, bool $update) {
if (isset($_POST['guide_keyword'])) {
update_post_meta($post_ID, 'guide_keyword', sanitize_text_field($_POST['guide_keyword']));
}
}
我确实复制了函数签名,但是当我保存帖子时它会抛出一个ArgumentCountError(所以我知道函数正在被调用并且钩子正在“工作”)。
例外
Fatal error: Uncaught ArgumentCountError: Too few arguments to function saveGuideMeta(), 1 passed in public_html/wp-includes/class-wp-hook.php on line 288 and exactly 3 expected
好像save_post_guide 钩子没有传递三个参数,只有一个。
我只是在保存帖子时尝试更新帖子元数据。我在这里做错了什么?
【问题讨论】: