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
Add a comment  | 

1 Answer 1

Reset to default 3

The 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
Add a comment  | 

1 Answer 1

Reset to default 3

The 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