Skip Navigation

[Resuelto] Set the Default Form Title

Este hilo está resuelto. Aquí tiene una descripción del problema y la solución.

Problem:

The issue here is that the user wanted to dynamically generate their post title based on the custom field inputs.

Solution:

This can be done by using the hook below.

function ttd_save_data_action($post_id, $form_data){
            // Change your CRED Form "ID" accordingly below
            if ($form_data['id']==ID){
               
                //Declare the content of your variables, change "your_custom_field_slug" accordingly
                $custom_value = get_post_meta( $post_id, 'wpcf-your_custom_field_slug', true );//get posts' Date field value (timestamp)
                $custom_title = gmdate("m-d-Y", $custom_value);//convert timestamp to m-d-y for output
                //collect data and define new title
                $my_post = array(
                    'ID'               => $post_id,
                    'post_title'   => $custom_title,
                    'post_name' => $custom_title,
                   
                );
               
                // Update the post into the database
                wp_update_post( $my_post );
               
            }
        }
    add_action('cred_save_data', 'ttd_save_data_action',10,2);

Ofcourse this will need to be adopted to fit your case but this is generally how it is done

This support ticket is created hace 4 años, 10 meses. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

Etiquetado: 

This topic contains 6 respuestas, has 2 mensajes.

Last updated by paulB-10 hace 4 años, 10 meses.

Assisted by: Shane.

Autor
Mensajes
#1272773
DivisionPostTitle.png

Creating a post form and want to set the Post title to the concatenation of 2 fields
Gender and Age Group
e.g.
Geneder Mens slug gender
Age Group Open slug age-group
Post Title Mens Open Desired title = gender + space + age-group

I currently have a php function that does this but it would be better if the code or configuration is in the form so it always gets moved with the form.

Thanks in advance of your response

#1272825

Shane
Supporter

Languages: Inglés (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Paul,

Thank you for contacting our support forum.

Are you saying you want to set the default title of the form when the user loads up the page with the form correct?

If so then no it is not possible especially since the items would've not yet been entered.

The best way to do this is to set the value attribute using JS when the user finish enters the information in the fields that you'll be pulling the data from.

Thanks,
Shane

#1272829

The code that is working for me is in the toolset -> settings -> custom code
function to set the post title.
I saw the function on another support ticket.
This works for me but, as previously mentioned if I could make it part of the form then the code would always be with the form when the form is moved etc.

  if ($form_data['id']==70)
    {
        $c1 = get_post_meta($post_id, 'wpcf-gender', true);
        $c2 = get_post_meta($post_id, 'wpcf-age-group', true);
        
  
       $title= $c1. ' ' . $c2;
  
        $slug = sanitize_title($title);
  
  
           $args = array('ID' => $post_id, 
                                   'post_title' => $title, 
                                   'post_name' => $slug
                          );
  
        wp_update_post($args);
#1272831

Shane
Supporter

Languages: Inglés (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Paul,

This code will always target the form given that the ID of the form remains unchanged.

What do you mean by "when the form is moved "

Thanks,
Shane

#1272851

In the situation where you develop the form in a development site and then start migrating the form through testing and then to production. It would be better if the code was packaged with the form so they always stay together.

#1272961

Shane
Supporter

Languages: Inglés (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Paul,

If its a case where the website itself is migrated then the ID should always remain the same.

In any case this is how it has to be done by using the form ID.

Thanks,
Shane

#1273659

My issue is resolved now. Thank you!

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.