Navigation überspringen

[Gelöst] Custom post title change when edited from the front-end form.

This support ticket is created vor 1 Jahr, 5 Monaten. 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.

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

Zeitzone des Unterstützers: Asia/Kolkata (GMT+05:30)

Dieses Thema enthält 5 Antworten, hat 3 Stimmen.

Zuletzt aktualisiert von Minesh vor 1 Jahr, 5 Monaten.

Assistiert von: Minesh.

Author
Artikel
#2686287

Hi,

Here is the script I used to custom the post title when I'm creating it, but how can I make it working also with the editing form ?

<?php
/**
* New custom code snippet (replace this with snippet description).
*/

toolset_snippet_security_check() or die( 'Direct access is not allowed' );

// Put the code of your snippet below this comment.

add_action('cred_save_data', 'func_add_movie_title', 10, 2);

function func_add_movie_title($post_id, $form_data)
{
if ($form_data['id'] == 408) {
$movie_title = isset($_POST['wpcf-original-name']) ? $_POST['wpcf-original-name'] : '';
$movie_sub_title = isset($_POST['wpcf-original-sub-name']) ? $_POST['wpcf-original-sub-name'] : '';
$title = $movie_title . '-' . $movie_sub_title;

$args = array('ID' => $post_id, 'post_title' => $title);
wp_update_post($args);
}
}

Thanks for your help.

#2686310

Nigel
Unterstützer

Sprachen: Englisch (English ) Spanisch (Español )

Zeitzone: Europe/London (GMT+01:00)

Hi there

What is the ID of the edit form?

You should just need to check for either the publish form (id 408) or the edit form (e.g. id 123).

Then the code would look like:

add_action('cred_save_data', 'func_add_movie_title', 10, 2);
function func_add_movie_title($post_id, $form_data)
{
    if (in_array($form_data['id'], [ 408, 123]) ) { // Edit Form IDs
        $movie_title = isset($_POST['wpcf-original-name']) ? $_POST['wpcf-original-name'] : '';
        $movie_sub_title = isset($_POST['wpcf-original-sub-name']) ? $_POST['wpcf-original-sub-name'] : '';
        $title = $movie_title . '-' . $movie_sub_title;

        $args = array('ID' => $post_id, 'post_title' => $title);
        wp_update_post($args);
    }
}
#2686405

Thank you Nigel,
Unfortunately, it does not update the names on the edit form (I chose the right ID)...
Any idea ?

Thanks for your help.

#2686428

Minesh
Unterstützer

Sprachen: Englisch (English )

Zeitzone: Asia/Kolkata (GMT+05:30)

Can you please share problem URL where I can see the edit form and what fields does not updated, please share steps that should help me to see the issue.

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I have set the next reply to private which means only you and I have access to it.

#2686434

Hi Minesh.

I’m still working locally with MampPro.
How can we do then ?

#2686436

Minesh
Unterstützer

Sprachen: Englisch (English )

Zeitzone: Asia/Kolkata (GMT+05:30)

You can send me duplicator copy of your site and also give details on what page you added the edit form and steps that should help me to see the issue.

More info:
- https://toolset.com/faq/provide-supporters-copy-site/

I have set the next reply to private which means only you and I have access to it.