最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

database - Any risk to changing WP table col CHARACTER_MAXIMUM_LENGTH?

programmeradmin2浏览0评论

I made a li'l module to help myself develop sites for various clients, and one thing it provides is an easy template for custom post types. It allows me to register post types much more easily and handles a lot of the default values I'd otherwise have to set up to get a nice post listing page and so forth.

Currently, it allows post type IDs of arbitrary lengths. I don't remember why I made this decision three years ago when I wrote the module, but in order to achieve this, it has to expand the wp_posts -> post_type column in the event that the desired post_type value is greater than CHARACTER_MAXIMUM_LENGTH.

Well, lo & behold, today I visited a site I worked on and somehow or other (an auto security update released before 5.5 maybe?), various things were broken. On investigation, the post_type values had been clipped, resulting in nothing coming out of the query.

Did WP reset the CHARACTER_MAXIMUM_LENGTH perhaps? Is what I'm doing an unstable way of solving this problem (as opposed to, say, clipping or hashing post_type values to preserve arbitrary length)?

I made a li'l module to help myself develop sites for various clients, and one thing it provides is an easy template for custom post types. It allows me to register post types much more easily and handles a lot of the default values I'd otherwise have to set up to get a nice post listing page and so forth.

Currently, it allows post type IDs of arbitrary lengths. I don't remember why I made this decision three years ago when I wrote the module, but in order to achieve this, it has to expand the wp_posts -> post_type column in the event that the desired post_type value is greater than CHARACTER_MAXIMUM_LENGTH.

Well, lo & behold, today I visited a site I worked on and somehow or other (an auto security update released before 5.5 maybe?), various things were broken. On investigation, the post_type values had been clipped, resulting in nothing coming out of the query.

Did WP reset the CHARACTER_MAXIMUM_LENGTH perhaps? Is what I'm doing an unstable way of solving this problem (as opposed to, say, clipping or hashing post_type values to preserve arbitrary length)?

Share Improve this question asked Aug 14, 2020 at 23:46 Luke SawczakLuke Sawczak 1034 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 2

The post_type field is an internal feld, you shouldn't be giving it values that require longer column lengths, and there's no need for it to be user facing.

WP allows you to override everything about it, from the query variable name, rewrite rules, to the wording displayed.

But more importantly, you shouldn't modify WP core. That goes for the database table schema too. WP will overwrite your changes when it calls dbDelta and restores the canonical database schema as part of the update process. At which point your column will get truncated. You might be able to get away with adding indexes at best, adding custom tables is fine.

So:

Did WP reset the CHARACTER_MAXIMUM_LENGTH perhaps?

Yes

Is what I'm doing an unstable way of solving this problem?

Yes

(as opposed to, say, clipping or hashing post_type values to preserve arbitrary length)

You shouldn't need more than 20 characters for a post_type, perhaps your auto-generated post type names are too verbose.

I wrote a plugin that registered thousands of custom post types in order to answer a question asked on this site, you'll face major PHP memory and performance issues long before you exhaust the 20 character namespace ( generating and transferring the markup for the admin menu gets problematic after 200, it breaks at a certain point, past 1000 it struggles despite no actual posts in the database for the CPT's

发布评论

评论列表(0)

  1. 暂无评论