Skip Navigation

[Resolved] Titles not being created properly

This support ticket is created 4 years, 2 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 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

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

This topic contains 12 replies, has 3 voices.

Last updated by larryL 4 years, 1 month ago.

Assisted by: Waqar.

Author
Posts
#1793801

I have a function that is supposed to grab the custom field and use that as the post title:


// Dynamically populate existing VIN data for existing vehicle update
 
add_filter( 'wpt_field_options', 'func_to_dynamically_populate_vin', 10, 3);
function func_to_dynamically_populate_vin( $options, $title, $type ){
    switch( $title ){
        case 'existing vin':
            $options = array();
   
            // add first empty value
            $options[] = array('#value' => '', '#title' => '---');
   
            // get all VIN post items
            $args = array( 'post_type' => 'vehicle', 'posts_per_page' => -1, 'post_status' => 'publish','orderby' => 'title' );
   
            $results = get_posts( $args );
            if ( $results ) {
                foreach ( $results as $post ) {
                    $options[] = array('#value' => $post->ID, '#title' => $post->post_title);
                }
            }
   
        break;
    }
    return $options;
}

What am I missing here? The 'vin' field is supposed to write to the post title. Thanks!

#1793851

Hello,

I have tried the same codes you mentioned above in my localhost, it works fine, please check these in your website:
1) Make sure you are using the latest version of Toolset plugins, you can download them here:
https://toolset.com/account/downloads/

2) In case it is a compatibility problem, please deactivate all other plugins, and switch to wordpress default theme 2020, deactivate all custom PHP/JS code snippets, and test again

3) Also check if there is any PHP/JS error in your website:
https://toolset.com/documentation/programmer-reference/debugging-sites-built-with-toolset/

4) If the problem still persists, please provide database dump file(ZIP file) of your website, you can put the package files in your own google drive disk, share the link only, also point out the problem page URL, I need to test and debug it in my localhost, thanks
https://toolset.com/faq/provide-supporters-copy-site/

#1794017

Actually, what I did was the wrong function altogether so technically the function was fine but it wasn't doing what I wanted it to do.

Here is what I have so far:

//Force title for Add Record from VIN field.

add_action('cred_save_data', 'build_vin_title', 10, 2);
function build_vin_title($post_id, $form_data) {
  
$forms = array( 8712,6944,12486,942,937 );
if ( in_array($form_data['id'], $forms) ){ 
$vin = get_post_meta($post_id, 'wpcf-vin', true);
$locale = get_post_meta($post_id, 'wpcf-vehicle-location', true);
  
$post_title=$vin. ' ' .$locale ;
$slug = sanitize_title($post_title);
wp_update_post(array('ID'=>$post_id, 'post_title'=>$post_title,'post_name' => $slug));
}
}

What is happening now is the title is being replaced (it was simply saying CRED - blah blah blah) with just the post id #.
Thanks!

#1794053

I have tried your custom PHP codes in my localhost, it works fine in my theme file "functions.php", please make sure you have put it in your theme file "functions.php", and test again

#1794847

Yes that is where it is.

#1794927

As I mentioned above, it works fine in my localhost, please check these:
1) Make sure you are using the latest version of Toolset plugins, you can download them here:
https://toolset.com/account/downloads/

2) In case it is a compatibility problem, please deactivate all other plugins, and switch to wordpress default theme 2020, deactivate other custom PHP snippets, and test again

3) Also check if there is any PHP error in your website:
https://toolset.com/documentation/programmer-reference/debugging-sites-built-with-toolset/

#1794997

I don't see how this could be a compatibility problem if I have other functions that do exactly the same thing.

#1795143

Please provide a full copy of your website in below private message box, also point out the problem page URL and form URL, where I can edit your PHP codes, thanks

#1796503

Wouldn't it be easier (and safer) just to give you access to the site?

#1797741

Hi,

Luo is on vacation, so I'll be following up on this ticket.

I already have the admin access to your website, but can you please share the link to a page where this form can be seen and tested?

regards,
Waqar

#1799107

Sure, thanks Waqar,

You can see the posts here - /wp-admin/edit.php?post_type=vehicle

The cred is here - /wp-admin/post.php?post=8712&action=edit&classic-editor

The form is here - /add-car/

The results display on the home page and here - /garage-counts/ (BTW - you can see that because it stopped working there is a test post missing the 'vin' because it pulls from the title)

This might just be something silly that I missed. But I tried redoing it several times.

#1802883

Thank you for sharing these details.

I tested the form and noticed that the ID of the post selected in the "Vehicle Location" field is correctly being used to create the new post's title.
( please check the newly created Vehicle post "6927" )

As for the Vin part, that is not being included in that title, that is due to another function, in the theme's "functions.php" file


add_action('cred_save_data', 'copy_location_to_multiline_field',10,2);
function copy_location_to_multiline_field($post_id, $form_data)
{
    // if a specific form
    if ($form_data['id']==8712)
    {
        if (isset($_POST['wpcf-vehicle-location']))
        {
            // add it to saved post meta
            update_post_meta($post_id, 'wpcf-vin', $_POST['wpcf-tmna-location']);
        }
    }
} 

This function sets the empty value to the "wpcf-vin" field, as this form has no "wpcf-tmna-location" field.

As a result, when the "build_vin_title" executes the "wpcf-vin" field already has the empty value set and so no vin is included in the title.

#1803927

My issue is resolved now. Thank you!