WordPress / gutenberg

The Block Editor project for WordPress and beyond. Plugin is available from the official repository.
https://wordpress.org/gutenberg/
Other
10.56k stars 4.22k forks source link

Error when editing custom post type with non-Latin slug in Gutenberg: "You attempted to edit an item that doesn't exist." #67358

Open mafiayemakhfi opened 3 days ago

mafiayemakhfi commented 3 days ago

Description

When attempting to edit a custom post type with a Persian slug in the Gutenberg editor, I encounter the error message:

"You attempted to edit an item that doesn't exist. Perhaps it was deleted?"

The post is still accessible via its URL, and no data appears to be lost. This issue seems to be related to the handling of slugs containing non-Latin characters in the Gutenberg editor.

Step-by-step reproduction instructions

  1. Create a custom post type (CPT) with a Persian slug.
  2. Example: my_custom_post_type with a slug like ویدیو (or any Persian characters).
  3. Permalink structure should be /%postname%/ .
  4. Publish a post in that CPT.
  5. Attempt to edit the post using the Gutenberg editor by navigating to the post editing screen.
  6. The error message "You attempted to edit an item that doesn't exist" appears.

    
    $video_labels = array(
            'name'                => _x('Videos', 'Post Type General Name', 'test'),
            'singular_name'       => _x('Video', 'Post Type Singular Name', 'test'),
            'menu_name'           => __('Videos', 'test'),
            'parent_item_colon'   => __('Video :', 'test'),
            'all_items'           => __('All Videos', 'test'),
            'view_item'           => __('View Video', 'test'),
            'add_new_item'        => __('Add Video', 'test'),
            'add_new'             => __('Add Video', 'test'),
            'edit_item'           => __('Edit Video', 'test'),
            'update_item'         => __('Update Video', 'test'),
            'search_items'        => __('Search Video', 'test'),
            'not_found'           => __('Video Not Found', 'test'),
            'not_found_in_trash'  => __('No Video Found In Trash', 'test'),
        );
    
        // Register Video Post Type
        register_post_type(
            'video',
            array(
                'labels'        => $video_labels,
                'public'        => true,
                'supports'      => array ( 'comments', 'title', 'editor', 'thumbnail','revisions' ),
                'has_archive'   => true,
                'show_in_rest'  => true,
                'rewrite'       => array('slug' => 'ویدیو'),
                'taxonomies'    => array('category', 'post_tag', 'artist_cat'),
                'menu_icon'     => 'dashicons-video-alt3',
                'menu_position' => 5
            )
        );


### Screenshots, screen recording, code snippet

_No response_

### Environment info

WP Version | 6.7.1
-- | --
Site Language | en_US
User Language | en_US
Timezone | +00:00
Home URL | http://localhost
Site URL | http://localhost
Permalink structure | /%postname%/
Is this site using HTTPS? | No
Is this a multisite? | No
Can anyone register on this site? | No
Is this site discouraging search engines? | No
Default comment status | Open
Environment type | production
User count | 1
Communication with WordPress.org | WordPress.org is reachab

### Please confirm that you have searched existing issues in the repo.

- [x] Yes

### Please confirm that you have tested with all plugins deactivated except Gutenberg.

- [x] Yes

### Please confirm which theme type you used for testing.

- [ ] Block
- [x] Classic
- [ ] Hybrid (e.g. classic with theme.json)
- [ ] Not sure
SainathPoojary commented 3 days ago

Hey @mafiayemakhfi,

I confirm that I was able to reproduce the bug in the environment described below. I used the code snippet provided in the description to create a custom post type (CPT).

Environment

https://github.com/user-attachments/assets/c9e19e35-405a-4919-830e-f7c178f0f6ae

himanshupathak95 commented 3 days ago

Hey @mafiayemakhfi, Thanks for bringing this up.

I was able to reproduce the issue following the above-mentioned steps. Here are the details -

Environment

Screencast -

https://github.com/user-attachments/assets/2de8c996-423b-4553-9249-18b3d56027f3