[wp-trac] [WordPress Trac] #46010: Auto-generated term slugs can be greater than 200 characters, giving "Could not insert term into the database." error
WordPress Trac
noreply at wordpress.org
Wed Jan 16 14:37:23 UTC 2019
#46010: Auto-generated term slugs can be greater than 200 characters, giving "Could
not insert term into the database." error
--------------------------+-----------------------------
Reporter: mikejolley | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Taxonomy | Version:
Severity: normal | Keywords:
Focuses: |
--------------------------+-----------------------------
When a slug is not user defined, WordPress attempts to generate it from
the term name within `wp_insert_term`. If the slug exists, when inserting
subcategories, WordPress prefixes the slug with the top level term name.
https://core.trac.wordpress.org/browser/tags/5.0.2/src/wp-
includes/taxonomy.php#L2093
Because of this, long term names can go over the slug length limit and
error. WordPress admin simply shows:
> Could not insert term into the database.
There is no reasoning provided, and when using wp_insert_term
programatically it's hard to know what's at fault.
This issue is more apparent when using cyrillic characters since they are
stored encoded in the DB.
Take "Категория на продукта" as an example. In the database this gets
stored as:
{{{
%d0%ba%d0%b0%d1%82%d0%b5%d0%b3%d0%be%d1%80%d0%b8%d1%8f-%d0%bd%d0%b0-%d0%bf%d1%80%d0%be%d0%b4%d1%83%d0%ba%d1%82%d0%b0
}}}
This is 116 characters. The maximum allowed slug length defined in the
wp_terms database schema is 200 characters.
Steps to reproduce:
- Add a top level category "Категория на продукта"
- Add another "Категория на продукта" term as a subcategory of "Категория
на продукта"
- See error
This is what WordPress attempted to insert into the database:
{{{
(
[name] => Категория на продукта
[slug] =>
%d0%ba%d0%b0%d1%82%d0%b5%d0%b3%d0%be%d1%80%d0%b8%d1%8f-%d0%bd%d0%b0-%d0%bf%d1%80%d0%be%d0%b4%d1%83%d0%ba%d1%82%d0%b0-%d0%ba%d0%b0%d1%82%d0%b5%d0%b3%d0%be%d1%80%d0%b8%d1%8f-%d0%bd%d0%b0-%d0%bf%d1%80%d0%be%d0%b4%d1%83%d0%ba%d1%82%d0%b0
[term_group] => 0
)
}}}
The slug is too long. We either need error checking for this, or we need
to truncate the slug length to avoid the issue and keep slug < 200 chars.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/46010>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list