admin管理员组文章数量:1130349
I have a custom field called _my_description
The idea is when a form is submitted the data from the form is also put into this field.
Here's my code
add_action( 'gform_post_submission_10', 'set_post_content', 10, 2 );
function set_post_content( $entry, $form ) {
$post = get_post( $entry['post_id'] );
$post-> _my_description = $entry[1] . ', ' . $entry[11] . ', ' . $entry[14] . ', ' . $entry[13] . ', ' . $entry[12] . ', ' . $entry[16] . ', ' . $entry[15] . $entry[19];
update_post_meta( $post );
}
If I have it go to the post_content with wp_update_post it works fine, but trying to get it to go to a custom field it wont work. The fields were created using this plugin / Anyone see why this isn't working please?
Fixed Thanks If anyone needs the code in future here it is
add_action( 'gform_post_submission_10', 'set_post_content', 10, 2 );
function set_post_content( $entry, $form ) {
$post = get_post( $entry['post_id'] );
update_post_meta( $post->ID, '_my_description', $entry[1] . ', ' . $entry[11] . ', ' . $entry[14] . ', ' . $entry[13] . ', ' . $entry[12] . ', ' . $entry[16] . ', ' . $entry[15] . $entry[19] );
}
I have a custom field called _my_description
The idea is when a form is submitted the data from the form is also put into this field.
Here's my code
add_action( 'gform_post_submission_10', 'set_post_content', 10, 2 );
function set_post_content( $entry, $form ) {
$post = get_post( $entry['post_id'] );
$post-> _my_description = $entry[1] . ', ' . $entry[11] . ', ' . $entry[14] . ', ' . $entry[13] . ', ' . $entry[12] . ', ' . $entry[16] . ', ' . $entry[15] . $entry[19];
update_post_meta( $post );
}
If I have it go to the post_content with wp_update_post it works fine, but trying to get it to go to a custom field it wont work. The fields were created using this plugin http://justcustomfields/ Anyone see why this isn't working please?
Fixed Thanks If anyone needs the code in future here it is
add_action( 'gform_post_submission_10', 'set_post_content', 10, 2 );
function set_post_content( $entry, $form ) {
$post = get_post( $entry['post_id'] );
update_post_meta( $post->ID, '_my_description', $entry[1] . ', ' . $entry[11] . ', ' . $entry[14] . ', ' . $entry[13] . ', ' . $entry[12] . ', ' . $entry[16] . ', ' . $entry[15] . $entry[19] );
}
Share
Improve this question
edited Feb 3, 2018 at 19:12
Chazlie
asked Feb 3, 2018 at 18:54
ChazlieChazlie
351 silver badge8 bronze badges
1 Answer
Reset to default 3The function signature for update_post_meta() looks as follows:
update_post_meta( int $post_id, string $meta_key, mixed $meta_value, mixed $prev_value = '' )
So instead of
update_post_meta( $post );
you need to use
update_post_meta( $post->ID, 'my_post_meta_key', $content_you_want_to_add );
I can only assume that you want to add this description to post meta. For that you'd use
update_post_meta( $post->ID, '_my_post_description', $entry[1] . ', ' ...
I have a custom field called _my_description
The idea is when a form is submitted the data from the form is also put into this field.
Here's my code
add_action( 'gform_post_submission_10', 'set_post_content', 10, 2 );
function set_post_content( $entry, $form ) {
$post = get_post( $entry['post_id'] );
$post-> _my_description = $entry[1] . ', ' . $entry[11] . ', ' . $entry[14] . ', ' . $entry[13] . ', ' . $entry[12] . ', ' . $entry[16] . ', ' . $entry[15] . $entry[19];
update_post_meta( $post );
}
If I have it go to the post_content with wp_update_post it works fine, but trying to get it to go to a custom field it wont work. The fields were created using this plugin / Anyone see why this isn't working please?
Fixed Thanks If anyone needs the code in future here it is
add_action( 'gform_post_submission_10', 'set_post_content', 10, 2 );
function set_post_content( $entry, $form ) {
$post = get_post( $entry['post_id'] );
update_post_meta( $post->ID, '_my_description', $entry[1] . ', ' . $entry[11] . ', ' . $entry[14] . ', ' . $entry[13] . ', ' . $entry[12] . ', ' . $entry[16] . ', ' . $entry[15] . $entry[19] );
}
I have a custom field called _my_description
The idea is when a form is submitted the data from the form is also put into this field.
Here's my code
add_action( 'gform_post_submission_10', 'set_post_content', 10, 2 );
function set_post_content( $entry, $form ) {
$post = get_post( $entry['post_id'] );
$post-> _my_description = $entry[1] . ', ' . $entry[11] . ', ' . $entry[14] . ', ' . $entry[13] . ', ' . $entry[12] . ', ' . $entry[16] . ', ' . $entry[15] . $entry[19];
update_post_meta( $post );
}
If I have it go to the post_content with wp_update_post it works fine, but trying to get it to go to a custom field it wont work. The fields were created using this plugin http://justcustomfields/ Anyone see why this isn't working please?
Fixed Thanks If anyone needs the code in future here it is
add_action( 'gform_post_submission_10', 'set_post_content', 10, 2 );
function set_post_content( $entry, $form ) {
$post = get_post( $entry['post_id'] );
update_post_meta( $post->ID, '_my_description', $entry[1] . ', ' . $entry[11] . ', ' . $entry[14] . ', ' . $entry[13] . ', ' . $entry[12] . ', ' . $entry[16] . ', ' . $entry[15] . $entry[19] );
}
Share
Improve this question
edited Feb 3, 2018 at 19:12
Chazlie
asked Feb 3, 2018 at 18:54
ChazlieChazlie
351 silver badge8 bronze badges
1 Answer
Reset to default 3The function signature for update_post_meta() looks as follows:
update_post_meta( int $post_id, string $meta_key, mixed $meta_value, mixed $prev_value = '' )
So instead of
update_post_meta( $post );
you need to use
update_post_meta( $post->ID, 'my_post_meta_key', $content_you_want_to_add );
I can only assume that you want to add this description to post meta. For that you'd use
update_post_meta( $post->ID, '_my_post_description', $entry[1] . ', ' ...
本文标签: functionsupdatepostmeta for custom field not working upon form submission
版权声明:本文标题:functions - update_post_meta for custom field not working upon form submission 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/questions/1749116058a2318213.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


发表评论