如何构建 WordPress 插件以从自定义数据库中提取数据以显示为帖子?
我有一个结构化数据数据库,我想在 WordPress 中显示为帖子。我可以将它们导入到 wordpress 数据库中,但随后我必须使数据镜像与主数据库保持同步,这会增加各种复杂性。
我一直无法找到正确的操作挂钩来覆盖它们从中提取的数据库,并且自定义帖子类型功能听起来像我想要的,但似乎只有在从 wordpress 数据库中提取时才有意义。
我可以只使用自定义模板标签来显示我的数据,但这些帖子仍然会从 WordPress 数据库中提取。
我看过一些 WordPress 的房地产列表插件和运动队管理插件,因为这似乎是一个类似的问题,即使我不处理房地产列表或运动队,但它们仍然将信息存储在 WordPress 数据库中。
除了分叉 wordpress 来扰乱帖子和查询类(这看起来像兔子洞)之外,我不想继续下去,我的选择是什么?解决相同问题的其他插件也很有用。
我是 WordPress 开发新手,但不是 Web 开发新手。
编辑:如果有必要或者使事情变得更简单,我可以接受,但将自定义数据与 WordPress 放在同一个数据库中并不理想。
I have a database of structured data I want to display in wordpress as posts. I could import them into the wordpress database but then I would have to keep that mirror of the data in sync with the master database which would add all sorts of complications.
I haven't been able to find the right action hooks to override the db they are pulled from and the custom post type functionality sounds like what I want but seems to only make sense when pulling from the wordpress database.
I could just use custom template tags to display my data, but those posts would still be pulled from the wordpress db.
I've looked at some real estate listing plugins and sports team management plugins for wordpress as that seems like a similar problem, even though I'm not dealing with real estate listings or sports teams but they still store the information in the wordpress db.
Beyond forking wordpress to mess with the post and query classes which seems like rabbit hole i don't want to go down what are my options? Other plugins solving the same problem would also be useful.
I'm new to wordpress development but not web development.
edit: I would be acceptable but not ideal to have the custom data in the same db as wordpress if that's necessary or makes things simpler.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以在 WordPress 中创建表并与这些表进行交互,就像与任何其他数据库表一样。 WP 附带了许多有用的功能来节省您的时间。要安装初始表,您需要使用
dbdelta
函数。 Codex 给出了一个示例:请参阅 http://codex.wordpress.org/Creating_Tables_with_Plugins 了解更多信息。
接下来,对于任何 CRUD 函数,您将需要使用 WP_Query 类。 Codex 很好地解释了每个函数的工作原理:http://codex.wordpress.org/Function_Reference /WP_Query。
如果可能的话,我建议您开发具有自定义帖子类型功能的插件。如果你这样做,它会更好地与 WP 配合使用,其他插件也会更好地配合它,并且用户将更容易理解如何操作你的插件。法典中有一份很棒的文档,它解决了在 WP 数据库中不必要地创建更多表的问题,但我似乎找不到它。也许其他人可以指引你走向它。
You can create tables within WordPress and interact with those tables like you would any other database tables. WP ships with a number of helpful functions to save you time. To install the initial table, you want to use the
dbdelta
function. The codex gives this as an example:See http://codex.wordpress.org/Creating_Tables_with_Plugins for more.
Next, to any of your CRUD functions, you'll want to use the WP_Query class. The codex does a wonderful job explaining how each of these functions work: http://codex.wordpress.org/Function_Reference/WP_Query.
I would recommend developing your plugin with Custom Post Type functionality if at all possible. If you do so, it will just work better with WP, other plugins will work better with it, and it will be easier for users to understand how to manipulate your plugin. There was a great document in the codex that addressed not unnecessarily creating more tables in the WP database, but I cannot seem to find it. Maybe someone else can point you toward it.