如何列出表中的所有行并显示wordpress数据库中的特定列数据

Ale*_*vić 2 database wordpress plugins wpdb

我有一个名为wp_email_subscription的表,在内部表中我有来自订阅用户的电子邮件行.每行包含id,email和name列.

我还为插件创建了管理页面,我想列出订阅表中的所有电子邮件.

基本上我不知道如何使用wpdb函数,我已经从wp网站上读过wpdb指令,但我不明白.

我需要的是从wp_email_subscription和foreach行中选择all来显示列表中的email和name列.

Pra*_*ala 10

你必须在你的代码页中使用全局wpdp变量和get_result函数,就像这样......

global $wpdb;

$row = $wpdb->get_results( "SELECT * FROM wp_email_subscription");

    foreach ( $row as $row ) 
    { echo "email:".$row->email.";} //$row->your_column_name in table
Run Code Online (Sandbox Code Playgroud)

像这样你可以通过$ variable-> col_name访问所有列