不能在钩子函数中使用 get_post_meta()
Can't use get_post_meta() inside a hook function
我正在使用 {status}_{post_type}
挂钩,需要从 post:
获取自定义元数据
add_action( 'pending_book', function( $post_id, $post ) {
$foo = get_post_meta($post_id, 'book_author', true);
var_dump($foo);
}, 99, 2 );
但是returnstring(0) ""
post 是在前端使用 GravityForms 生成的。
我能做什么?
解决方法如下:GravityForm hook
add_action( 'gform_after_submission_13', function( $entry, $form ) {
$foo = get_post_meta($entry['post_id'], 'book_author', true);
var_dump($foo);
}, 10, 2 );
其中 13 是表单的 ID。
更多信息在这里:https://www.gravityhelp.com/documentation/article/gform_after_submission/
我正在使用 {status}_{post_type}
挂钩,需要从 post:
add_action( 'pending_book', function( $post_id, $post ) {
$foo = get_post_meta($post_id, 'book_author', true);
var_dump($foo);
}, 99, 2 );
但是returnstring(0) ""
post 是在前端使用 GravityForms 生成的。
我能做什么?
解决方法如下:GravityForm hook
add_action( 'gform_after_submission_13', function( $entry, $form ) {
$foo = get_post_meta($entry['post_id'], 'book_author', true);
var_dump($foo);
}, 10, 2 );
其中 13 是表单的 ID。
更多信息在这里:https://www.gravityhelp.com/documentation/article/gform_after_submission/