WordPress.org

Make WordPress Core

Opened 4 years ago

Closed 4 years ago

#12870 closed defect (bug) (fixed)

Edit page for custom post type not showing slug & pretty permalink

Reported by: vlasky Owned by: dd32
Milestone: 3.0 Priority: normal
Severity: normal Version: 3.0
Component: Posts, Post Types Keywords: has-patch
Focuses: Cc:

Description

I am using 3.0-beta1. I have registered a custom post type called 'mycustom'.

In permalink settings, I have a custom structure of:
/archives/%postname%/

When I edit a post of my custom post type, instead of seeing the text box that displays the slug underneath the title, I see the following:

Permalink: http://wp.remoteexperiments.com:808/wordpress/?post_type=mycustom&p=44 and then a button marked 'Change Permalinks'

Enclosed is a screenshot, and here is the code I have used to register the custom type. Note that I have tried both with and without the 'rewrite' option.

$supports = array( 'title', 'editor', 'custom-fields', 'revisions');

$args = array ('label' => ('MyCustom'),

'singular_label' => ('MyCustom'),
'_builtin' => false,
'public' => true,
'show_ui' => true,
'capability_type' => 'post',
'supports' => $supports,
'exclude_from_search' => true,
'hierarchical' => false

'rewrite' => array('slug' => 'mycustom')
);

register_post_type('mycustom', $args);

Attachments (3)

MyCustomPostType.PNG (69.0 KB) - added by vlasky 4 years ago.
Screen shot of editor showing missing slug when editing a custom post type under WP 3.0-beta1
link-template.php.diff (566 bytes) - added by duck_ 4 years ago.
12870.diff (2.5 KB) - added by duck_ 4 years ago.

Download all attachments as: .zip

Change History (13)

vlasky4 years ago

Screen shot of editor showing missing slug when editing a custom post type under WP 3.0-beta1

comment:1 uglyrobot4 years ago

  • Cc aaron@… added
  • Resolution set to invalid
  • Status changed from new to closed

You have to enable rewrites for that post type, as well as configure them how you want. Custom post types will not be added to the default rewrite rules unless you add them manually.

comment:2 vlasky4 years ago

  • Resolution invalid deleted
  • Status changed from closed to reopened

comment:3 vlasky4 years ago

  • Priority changed from normal to high
  • Severity changed from normal to major

Please read my report carefully - I included the option 'rewrite' when registering the custom post_type. I had tried both enabling and disabling that option.

After doing more research, I discovered that this issue was previously reported in ticket 12742 and patched in ticket 13865. Was this patch properly tested and rolled out in the last nightly build?

comment:4 follow-up: vlasky4 years ago

  • Priority changed from high to normal
  • Severity changed from major to normal

I changed this back to normal priority and severity so I don't seem overly self-important, but I just wanna say that it was wrong for uglyrobot to rush to declare this issue as 'invalid' without looking into it properly.

I also wish to note that another patch to address this problem was just released in 12895 by duck_

comment:5 duck_4 years ago

  • Keywords has-patch needs-testing added; slug permalinks removed

Managed to not read this properly when submitting #12895.

Anyway, problem is because you're editing a draft custom post type, only published custom post types show the pretty permalink. Patch attached.

duck_4 years ago

comment:6 in reply to: ↑ 4 uglyrobot4 years ago

Replying to vlasky:

I changed this back to normal priority and severity so I don't seem overly self-important, but I just wanna say that it was wrong for uglyrobot to rush to declare this issue as 'invalid' without looking into it properly.

In your sample code you had rewrites commented out. That was expected behavior without defining a rewrite and query_var.

comment:7 follow-up: dd324 years ago

  • Owner set to dd32
  • Status changed from reopened to accepted

See Also: #12742

Looks like i didn't catch it all..

I just noticed that the slug displayed may not be correct, for example, It showed /note/test/ in hte slug preview, and /note/test-6/ after a draft save when it realised test was already taken.

comment:8 dd324 years ago

r14068 /trunk/wp-includes/link-template.php: Correct sample URL's for custom post_type's. uses pretty permalinks if possible. Props duck_. See #12870

comment:9 in reply to: ↑ 7 duck_4 years ago

  • Keywords needs-testing removed

Replying to dd32:

I just noticed that the slug displayed may not be correct, for example, It showed /note/test/ in hte slug preview, and /note/test-6/ after a draft save when it realised test was already taken.

Problem was that autosave.js was not sending a new_slug to admin-ajax.php, if this isn't set then it defaults to empty string. get_sample_permalink(_html) use null as a default for this value, so even though a unique slug was retrieved in the get_sample_permalink function it was overwritten because $name (aka the new_slug) was not null. Fix sets default for unset new_slug to be null. Also move the check for a new name in get_sample_permalink to before the unique slug call so that the same problem doesn't happen when editing the permalink of an existing post (try this now and you'll see that the number suffix isn't added until save).

PS, the patch also includes minor optimisation of _get_page_link function from link-template.php

duck_4 years ago

comment:10 dd324 years ago

  • Resolution set to fixed
  • Status changed from accepted to closed

(In [14124]) Display the correct Slug in the permalink preview. Props duck_. Fixes #12870

Note: See TracTickets for help on using tickets.