WordPress:从小部件代码访问数据库

问题描述:

如何从小部件代码访问WordPress数据库并运行SQL? (我需要从小部件代码访问我的一个插件的设置)

How can I access to my WordPress database and run SQL from the widget code? (I need to access to the settings of one of my plugins from the widget code)

您可以检查 http://完整文档请参见codex.wordpress.org/Class_Reference/wpdb .在履历表中,您可以从小部件代码的任何部分执行以下操作:

You can check this http://codex.wordpress.org/Class_Reference/wpdb for full documentation. In resume you can do something like the follow from any part of your widget code:

global $wpdb;
$rows = $wpdb->get_results( "SELECT id, name FROM table" );