You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

WordPress自定义插件Admin Panel数据不显示问题排查求助

WordPress自定义插件表格无法显示数据排查求助

我在WordPress中开发了一个自定义插件,路径为E:\xampp\htdocs\wp_project\wp-content\plugins\booked-lbb-properties.php,用于展示wp_lbb_bookings表中的已预订房源数据,但后台管理面板内的表格无法正常显示数据。以下是插件完整代码、数据库字段类型信息,以及当前后台面板的显示效果截图,请帮忙分析错误原因:

插件代码

<?php
/*
Plugin Name: Booked LB&B Properties
Description: Display booked properties from wp_lbb_bookings table
*/
if (!class_exists('WP_List_Table')) {
    require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php';
}


// action function for above hook
function blbb_add_pages() {
    add_menu_page(
        __('Booked LB&B Properties', 'blbb'), 
        __('Booked LB&B Properties', 'blbb'), 
        'manage_options', 
        'blbb-bookings', 
        'blbb_bookings_page',
        46
    );
}
add_action('admin_menu', 'blbb_add_pages');

function blbb_bookings_page() {
    ?>
    <div class="wrap">
        <h2><?php _e('Booked LB&B Properties', 'blbb'); ?></h2>
        <?php
        global $wpdb;
        $table_name = $wpdb->prefix . 'lbb_bookings';
        $blbb_list_table = new BLBB_List_Table();
        $blbb_list_table->prepare_items();
        ?>
        <form id="blbb-bookings-form">
            <?php $blbb_list_table->search_box('Search Properties', 'search_id');?>
            <table><?php $blbb_list_table->display();?></table>
        </form>
    </div>
    <?php
}

class BLBB_List_Table extends WP_List_Table {
    function __construct() {
        global $status, $page;
        parent::__construct(array(
            'singular' => 'booking',
            'plural'   => 'bookings',
            'ajax'     => false
        ));
    }

    function column_default($item, $column_name) {
        switch ($column_name) {
            case 'booking_id':
            case 'lbb_property_type':
            case 'lbb_property_id':
            case 'user_id':
            case 'guest_name':
            case 'email':
            case 'phone':
            case 'address':
            case 'zip_code':
            case 'city':
            case 'country':
            case 'subscribe':
            case 'check_in_date':
            case 'check_out_date':
            case 'price':
            case 'nights':
            case 'transaction_id':
            case 'payment_intent':
            case 'payment_method':
            case 'payment_status':
            case 'session_id':
            case 'created_at':
                return $item[$column_name];
            default:
                return print_r($item, true);
        }
    }

    function get_columns() {
        $columns = array(
            'cb'                => '<input type="checkbox" />',
            'booking_id'        => __('Booking ID', 'blbb'), 
            'lbb_property_type' => __('LB&B Property Type', 'blbb'), 
            'lbb_property_id'   => __('LB&B Property ID', 'blbb'),    
            'user_id'           => __('User ID', 'blbb'),     
            'guest_name'        => __('Guest Name', 'blbb'),
            'email'             => __('Email', 'blbb'),
            'phone'             => __('Phone', 'blbb'),
            'address'           => __('Address', 'blbb'),
            'zip_code'          => __('Zip Code', 'blbb'),
            'city'              => __('City', 'blbb'),
            'country'           => __('Country', 'blbb'),
            'subscribe'         => __('Subscribe', 'blbb'), 
            'check_in_date'     => __('Check In Date', 'blbb'),
            'check_out_date'    => __('Check Out Date', 'blbb'),
            'price'             => __('Price', 'blbb'),
            'nights'            => __('Nights', 'blbb'), 
            'transaction_id'    => __('Transaction ID', 'blbb'), 
            'payment_intent'    => __('Payment Intent', 'blbb'), 
            'payment_method'    => __('Payment Method', 'blbb'), 
            'payment_status'    => __('Payment Status', 'blbb'), 
            'session_id'        => __('Session Id', 'blbb'), 
            'created_at'        => __('Created At', 'blbb'), 
        );
        return $columns;
    }

    function prepare_items() {
        global $wpdb;
        $table_name = $wpdb->prefix . 'lbb_bookings';
        $query = "SELECT * FROM $table_name";
        $orderby = !empty($_GET["orderby"]) ? mysql_real_escape_string($_GET["orderby"]) : 'ASC';
        $order = !empty($_GET["order"]) ? mysql_real_escape_string($_GET["order"]) : '';
        if (!empty($orderby) && !empty($order)) {
            $query .= ' ORDER BY ' . $orderby . ' ' . $order;
        }
        $totalitems = $wpdb->query($query);
        $perpage = 5;
        $paged = !empty($_GET["paged"]) ? mysql_real_escape_string($_GET["paged"]) : '';
        if (empty($paged) || !is_numeric($paged) || $paged <= 0) {
            $paged = 1;
        }
        $totalpages = ceil($totalitems / $perpage);
        if (!empty($paged) && !empty($perpage)) {
            $offset = ($paged - 1) * $perpage;
            $query .= ' LIMIT ' . (int) $offset . ',' . (int) $perpage;
        }
        $this->items = $wpdb->get_results($query);
        $this->set_pagination_args(array(
            "total_items" => $totalitems,
            "total_pages" => $totalpages,
            "per_page" => $perpage
        ));
    }
}

数据库字段类型

'booking_id'        => bigint(20)   
'lbb_property_type' => varchar(255) 
'lbb_property_id'   => int(255)   
'user_id'           => int(255)    
'guest_name'        => varchar(255)  
'email'             => varchar(255)   
'phone'             => varchar(255)   
'address'           => varchar(255) 
'zip_code'          => varchar(255)    
'city'              => varchar(255)    
'country'           => varchar(255) 
'subscribe'         => tinyint(1) 
'check_in_date'     => date
'check_out_date'    => date
'price'             => varchar(255)   
'nights'            => int(255) 
'transaction_id'    => varchar(255)
'payment_intent'    => varchar(255)
'payment_method'    => varchar(255)
'payment_status'    => varchar(50)  
'session_id'        => varchar(50)  
'created_at'        => timestamp

后台面板显示效果

后台管理面板

请帮忙分析哪里出现了错误,导致表格无法显示数据?


内容的提问来源于stack exchange,提问作者James Martin

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.22 04:45:56