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 http://justcustomfields.com/ 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] ); 
}
2

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] . ', ' ...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.