开发者

Creating tables with WP plugin

开发者 https://www.devze.com 2023-01-08 15:56 出处:网络
I\'m beginning to write wordpress plugins, and I\'ve found a situation 开发者_如何学JAVAwhere I need to create tables to continue. Can someone point to a decent tutorial on modifying Wordpress\'s data

I'm beginning to write wordpress plugins, and I've found a situation 开发者_如何学JAVAwhere I need to create tables to continue. Can someone point to a decent tutorial on modifying Wordpress's database?

Their usually excellent documentation seems lacking on this topic.


The WordPress Codex has a good article on creating database tables with Plugins.

Like Benoit said, most of the times wp_options is sufficient, but that article is a good guide to getting started with a custom table if you need it. First though, I'd advise you to look and see if it can logically be done without creating a new table. Custom Post Types can handle most of the heavy lifting for most content-related functions. The bottom of the Custom Post Types Codex entry has several good tutorials for getting started.


In WP, most plugins don't create new tables, but use the "wp_options" table, even when a new table would be "natural".

For example, the "WP acronyms" plugin. A table with 2 columns (acronym and definition) would be natural. But this plugin stores the acronyms in a single row of the "wp_options" table. When data is necessary, the content of this row is parsed and the fields are extracted (using a delimiter). You could consider using the same method.

0

精彩评论

暂无评论...
验证码 换一张
取 消