drnvcm3949
2014-06-23 11:09
浏览 113
已采纳

在WordPress中处理自定义表数据

I'm making a plugin for WordPress and it requires some custom tables of mine (or the data in them, to be specific). These tables are simple. They only contain an id and a varchar field. Do not mention meta fields. I am using custom tables for a reason. The problem is, I need to allow the user to edit the data in these tables. To insert, update and delete rows in the tables. How do I handle this in WordPress?

I can make my own custom pages and create a whole system for editing, inserting and updating them but that's a workaround since none of that would be native to WordPress.

The only thing I came up with is making them into custom post types and having WordPress let me use its native adding, editing and deleting menu (the same one used in posts, pages, etc.). Though then new problems would arise. I need to connect the post ids to the rows in the custom tables and be very careful when editing, updating and deleting to make sure that both the posts and my custom table data remain consistent with each other. And that's a whole new layer of complexity.

So I was wondering if there's an elegant way to handle these sorts of simple tables. If there isn't I'll find my own workaround.

EDIT:

The plugin I'm making is supposed to turn your WordPress site into a kind of an ad posting site. And I need the custom tables to provide details about the ads.

图片转代码服务由CSDN问答提供 功能建议

我正在为WordPress创建一个插件,它需要我的一些自定义表(或其中的数据,到 请明确点)。 这些表很简单。 它们只包含id和varchar字段。 不要提及元字段。 我使用自定义表是有原因的。 问题是,我需要允许用户编辑这些表中的数据。 在表中插入,更新和删除行。 我如何在WordPress中处理这个?

我可以创建自己的自定义页面并创建一个完整的系统来编辑,插入和更新它们,但这是一种解决方法,因为这些都不是原生的 WordPress。

我唯一想到的就是将它们变成自定义帖子类型,让WordPress让我使用它的原生添加,编辑和删除菜单(在帖子,页面中使用的相同) 等)。 虽然会出现新的问题。 我需要将post id连接到自定义表中的行,并且在编辑,更新和删除时要非常小心,以确保帖子和我的自定义表格数据保持一致。 这是一个全新的复杂层。

所以我想知道是否有一种优雅的方式来处理这些简单的表。 如果没有,我会找到自己的解决方法。

编辑:

我正在制作的插件应该是你的WordPress网站 进入一种广告发布网站。 我需要自定义表格来提供有关广告的详细信息。

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • douvcpx6526 2014-06-23 12:09
    已采纳

    refer this codex Wp_list_table. you can play with custom table data. for more you can go through an example plugin.

    点赞 打赏 评论

相关推荐 更多相似问题