Skip Navigation

[Resolved] Set the post ID as the default value of a custom field in Types

The Toolset Community Forum is closed, for technical support questions, please head on to our Toolset Professional Support (for paid clients), with any pre-sale or admin question please contact us here.
This support ticket is created 6 years, 9 months ago. There's a good chance that you are reading advice that it now obsolete.
This is the community support forum for Types plugin, which is part of Toolset. Toolset is a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients and people who registered for Types community support can post in it.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 10:00 - - - - -
- - - - - - -

Supporter timezone: Africa/Cairo (GMT+02:00)

This topic contains 1 reply, has 2 voices.

Last updated by Mohammed 6 years, 9 months ago.

Assisted by: Mohammed.

Author
Posts
#630322

Hello, I am working on a registration form in Types where all information is completed in a custom post type called "player". I created a custom field called "unique-number". I want this "unique-number" to have the post-id as the default value when creating a new post. Can you please advise on how to do this?

Thanks!

#630556

Hi,

This is not supported natively by Types. you will need to add some custom code to do that.

you can use the save_post hook to override the field value.

To avoid confusions, Note that, if the field slug is test-field, it will be stored in the database like this wpcf-test-field

Example:

//This code is not tested, it's the client responsibility to test it on his own
function my_project_updated_send_email( $post_id ) {
    $post_type = get_post_type($post_id);
if($post_type=='my_post_type')
{
    update_post_meta( $psot_id, 'wpcf-test-field', $post_id);
}
}
add_action( 'save_post', 'my_project_updated_send_email' );

You cna use the previous code, modify it to make to work for your request.

Thanks.

The forum ‘Types Community Support’ is closed to new topics and replies.