Skip Navigation

[Resolved] Append Title to another Post submitted through cred

This support ticket is created 7 years, 9 months ago. 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)

This topic contains 5 replies, has 2 voices.

Last updated by justinB-5 7 years, 9 months ago.

Assisted by: Shane.

Author
Posts
#415607

I am trying to: Append the title of another post to posts submitted through a CRED form. The post ID is stored in the database via another field.

I visited this URL: https://toolset.com/forums/topic/autofill-a-field-in-cred/

I expected to see: the answer

Instead, I got: Most of the answer. I am trying to specifically target the title of the post thats ID is stored in 'wpcf-g-doc-number'. Below is what I have so far, and if this is outside the scope of support I understand, just thought I'd give it a try. Thanks.

add_action('cred_save_data', 'my_save_data_action',10,2);
function my_save_data_action($post_id, $form_data)
{    
    //if  form
    if ($form_data['id']==299)
    {
        if (isset($_POST['g-doc-number']))
        {
            add_post_meta($post_id, 'wpcf-g-doc-number', $_POST['g-doc-number'], true); 
        }
        $my_post = array(
              'ID'           => $post_id,
              'post_title' => 'Enquiry re: '.get_the_title($post_id)  //This is where I'd like to get the title of the post with the ID stored in 'wpcf-g-doc-number'
          );
          
        // Update the post into the database
          wp_update_post( $my_post );
    }
}
#415638

Shane
Supporter

Languages: English (English )

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

Hi Justin,

Thank you for contacting our support forum.

I took a look at your code and saw 2 small issues 🙂

Could you change this line from

isset($_POST['g-doc-number'])

to

isset($_POST[wpcf-'g-doc-number'])

And this line from

'ID'           => $post_id,

to

'ID'           =>$_POST['g-doc-number'],

Please let me know if this helps.

Thanks,
Shane

#415645

Thanks Shane for the quick response. I was showing the whole function for clarity, but the first part is already working. The field used is a generic field and the only way I could get it to work was to omit the 'wpcf-'.

As for the rest, I tried combinations of both of the changes you recommended and I'm still getting 'Enquiry re: Auto Draft 8c9f.....' as the title on my new posts. Any other ideas?

Thanks in advance.

#415650

Shane
Supporter

Languages: English (English )

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

Hi Justin,

The post being created is it suppose to provide a title for another post ?

Meaning get_post_title is getting the title from $post_id .

This means that if the post with the id that stored in the $post_id variable does not have a title then it is going to provide an Auto Draft title for the other post.

Please let me know if this helps.

Thanks,
Shane

#415655

The other way around. The get_the_title needs to get the title from the post with ID given in the 'g-doc-number' field.

#415658

OK so I figured it out. Thanks for pushing me in the right direction Shane.

 $my_post = array(
              'ID'           => $post_id,
              'post_title' => 'Enquiry re: '.get_the_title($_POST['g-doc-number'])
          );
          
        // Update the post into the database
          wp_update_post( $my_post );


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