Skip Navigation

[Resolved] slugs always adding -2 at end

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

Problem:

I have a CRED form, I add below code in functions.php:

https://toolset.com/forums/topic/slugs-always-adding-2-at-end/#post-1219993

I am sure the post is new but don't know why the slugs always adding -2 at end.

Solution:

This is expected result of WordPress, for example:

https://toolset.com/forums/topic/slugs-always-adding-2-at-end/#post-1220205

Relevant Documentation:

This support ticket is created 5 years, 11 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.

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/Hong_Kong (GMT+08:00)

This topic contains 2 replies, has 2 voices.

Last updated by kelvinL-2 5 years, 11 months ago.

Assisted by: Luo Yang.

Author
Posts
#1219993

Dear Sir/Madam,

I have a CRED form, I add below code in functions.php

add_action('cred_save_data', 'my_save_data_action',10,2);
function my_save_data_action($post_id, $form_data)
{
    if ($form_data['id']==2775)
    {
       wp_update_post( array(
            'ID' => $post_id,
            'post_name' => $post_id
        ));
    }
}

I am sure the post is new but don't know why the slugs always adding -2 at end.

#1220205

Hello,

This is expected result of WordPress, for example, you can test it without Toolset form plugin, create a post in admin side, in section "Permalink", change the value to post's ID, save it, you will be able to see the same result:
the slugs always adding -2 at end.

In your case, I suggest you add a static text before post ID, for example, replace this line from:
'post_name' => $post_id

To:
'post_name' => 'post-' . $post_id

Then you will be able to get the post Permalink like these:
post-123
post-456
...

#1220623

My issue is resolved now. Thank you!