Skip Navigation

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

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

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 hace 7 años, 1 mes. 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.

Hoy no hay técnicos de soporte disponibles en el foro Juego de herramientas. Siéntase libre de enviar sus tiques y les daremos trámite tan pronto como estemos disponibles en línea. Gracias por su comprensión.

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)

Etiquetado: 

Este tema contiene 31 respuestas, tiene 3 mensajes.

Última actualización por Nashaat hace 7 años, 1 mes.

Asistido por: Noman.

Autor
Mensajes
#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?