Make WordPress Core

Opened 6 months ago

Closed 6 months ago

#62013 closed defect (bug) (worksforme)

the post_name field is not taken into account

Reported by: yperret's profile yperret Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: Posts, Post Types Keywords:
Focuses: Cc:

Description

it seems that the post_name field is never defined and takes the slug from the title.

After look, the control in wp_insert_post for if the field is defined doesn't work.

Code :

        $my_post = array(
            'post_title'    => wp_strip_all_tags("Logout"),
            'post_name '    => "logout-page",
            'post_content'  => "",
            'post_status'   => 'publish',
            'post_type'     => 'page'
        );
    
        $logout = wp_insert_post( $my_post );

Maybe the problem is located at the line 4281 in post.php

Change History (2)

#1 @the ank
6 months ago

Hello @yperret ,

I tried to replicate the issue and I found an error in the code mentioned above.

'post_name '    => "logout-page"

There is a space before the closing single quote. If you remove the space, it starts working as expected.

Correct Version -

'post_name' => "logout-page"

Regards

#2 @hellofromTonya
6 months ago

  • Milestone Awaiting Review deleted
  • Resolution set to worksforme
  • Status changed from new to closed
  • Version 6.6.1 deleted

Hello @yperret,

Welcome to WordPress Core's Trac.

As @the-ank noted (thank you!), there's an extra space in the supplied example code which will cause the problem you noted:

'post_name '    => "logout-page",

In testing the supplied code with the key as 'post_name', it works for me. Closing this ticket as worksforme. However, if the problem persists after changing the 'post_name' key, please reopen to share your findings.

Note: I'm also removing the Version as 6.6.1 did not include changes to this area of the code.

Note: See TracTickets for help on using tickets.