Skip Navigation

[Resolved] Custom post title from 5 different custom fields.

This thread is resolved. Here is a description of the problem and solution.

Problem:
Trying to auto-create post title base on 5 different custom fields.
Solution:
Custom solution here:
https://toolset.com/forums/topic/custom-post-title-from-5-different-custom-fields/page/2/#post-578300
Relevant Documentation:

This support ticket is created 7 years, 1 month 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
- 12:00 – 17:00 12:00 – 17:00 12:00 – 17:00 12:00 – 17:00 12:00 – 17:00 -
- 18:00 – 21:00 18:00 – 21:00 18:00 – 21:00 18:00 – 21:00 18:00 – 21:00 -

Supporter timezone: Asia/Karachi (GMT+05:00)

This topic contains 31 replies, has 3 voices.

Last updated by Nashaat 7 years, 1 month ago.

Assisted by: Noman.

Author
Posts
#897129

I saw that you have another Code but this didnt work too.


add_filter( 'wp_insert_post_data' , 'modify_post_title' , '99', 2 ); // Grabs the inserted post data so you can modify it.
 
function modify_post_title( $data, $postarr )
{
    //$post_id = $postarr['ID'];
    if($data['post_type'] == '0km' && isset($postarr['wpcf']) ) { 
         
        $field_1 = $postarr['wpcf']['car-manufacturer'];
        $field_2 = $postarr['wpcf']['car-name'];
        $field_3 = $postarr['wpcf']['car-version'];
        $field_4 = $postarr['wpcf']['model-year'];
         
         
        $title = '';
        if(isset($field_1) && $field_1 != '')
            $title .= $field_1 . ' ';
        if(isset($field_2) && $field_2 != '')
            $title .= $field_2 . ' ';
        if(isset($field_3) && $field_3 != '')
            $title .= $field_3 . ' ';
        if(isset($field_4) && $field_4 != '')
            $title .= $field_4 . ' ';
        if(isset($field_5) && $field_5 != '')
            $title .= $field_5;
             
        $data['post_title'] =  $title ; //Updates the post title to your new title.
    }
  return $data; // Returns the modified data.
}

Is there anything i am doing wrong.

I have replaced this following in your code

0km
car-manufacturer
car-name
car-version
model-year

#897187

After testing this out. Your code works only if i create a new post from WordPress dashboard then i can i see the right Title. but If i create a new post with CRED form, it generates a new Post with such Title ( CRED Auto Draft d0f8b201bbf07f2b377cf4b7b72ef75d ) then i need to open the post in WordPress Dashboard and click UPDATE to show the right Title

Is there anyway to solve this?