使用 WordPress 从数据库读取
我对 WordPress 很陌生,对 PHP 知之甚少。 我阅读了有关 PODS 的内容,并且知道如何创建 PODS 并使用页面/模板来显示数据。
我遇到的问题是,我创建的 PODS 使用通过 WP 仪表板输入的静态数据,我想要的是从数据库读取数据,我正在使用 MySql(与 WordPress 使用的数据库相同)。有没有办法使用 PODS 并从数据库读取数据,或者 wordpress 有更好的方法来处理来自数据库的数据?
谢谢
I am very new to WordPress, I have very little knowledge with PHP.
I read about PODS and I know how to create one and use pages / templates to display data.
The issue I am havingis, the PODS I was creating use static data entered via the WP dashboard, what I want is to read data from a database, I am using MySql (same DB that wordpress is using). is there a way to use PODS and read the data from the DB, or wordpress has a better way to handle data coming from the DB ?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在 WordPress 中读取数据库的常用方法如下:
获取全局变量 $wpdb
准备输出和SQL命令
<前>$输出=“”;
$sql = "SELECT ".$wpdb->前缀."posts.post_title,
“.$wpdb->前缀。”posts.post_name FROM “。
$wpdb-> 前缀。"帖子 WHERE ".$wpdb-> 前缀。
"posts.post_status='发布' AND ".$wpdb-> 前缀。
"posts.post_parent=0 AND ".$wpdb-> 前缀。
"posts.post_type='sometype'";
方法 get_results() 从数据库检索值
Usual way to read from database in WordPress is the following:
get global variable $wpdb
prepare the output and SQL command
method get_results() retrieves values from db
您应该查看 $wpdb 变量(和类)
http://codex.wordpress.org/Class_Reference/wpdb
请记住将其声明为全局的:
但是我不确定你想要什么。
我建议靠近 WordPress。
如果您想在不使用代码的情况下创建自己的自定义帖子类型,请使用 moretypes
You should Look into the $wpdb variable (and class)
http://codex.wordpress.org/Class_Reference/wpdb
Do remember to declare it a global:
I am however not sure what you want.
I advise staying close to wordpress.
If you want to create your own custom post types without using code use moretypes
Wordpress CSM 有一个非常好的与 db 一起使用的类,我认为更好的选择是学习 db 如何连接并从 mysql 获取数据
Wordpress CSM has a very good class to work with db, i think the better bet on this is learn how db connects and get data from mysql