一,加搜索功能

1,在’prepare_items’方法里加上以下代码

  1. if (isset($_REQUEST['page']) && isset($_REQUEST['s'])) {
  2. $args['s'] = $_REQUEST['s'];
  3. }

2,修改 “*-functionsproduct-functions.php”文件的 修改查询语句

if (isset($args['s'])) {
            $sql = 'SELECT * FROM ' . $wpdb->prefix . 'haozhuti_guestbook2 ' . ' WHERE name LIKE \'%' . $args['s'] . '%\'' . ' ORDER BY ' . $args['orderby'] . ' ' . $args['order'] .  ' LIMIT ' . $args['offset'] . ', ' . $args['number'];
            var_dump($sql);
            $items = $wpdb->get_results($sql);
        } else {
            $items = $wpdb->get_results('SELECT * FROM ' . $wpdb->prefix . 'haozhuti_guestbook2 ORDER BY ' . $args['orderby'] . ' ' . $args['order'] . ' LIMIT ' . $args['offset'] . ', ' . $args['number']);
        }

二,屏幕选项

1,在类 ‘Hzt_Order_Management_Admin_Menu’ 中添加如下成员变量

public  $list_table = null;

image.png

2,在 Hzt_Order_Management_Admin_Menu 的构造方法下加如下代码

add_filter('set-screen-option', array($this, 'set_screen'), 10, 3);

image.png

3,修改 Hzt_Order_Management_Admin_Menu 的 admin_menu 方法

$hook = add_submenu_page('hztorder', __('订单管理', 'haozhuti'), __('订单管理', 'haozhuti'), 'manage_options', 'hztorder', array($this, 'plugin_page'));
add_action("load-$hook", array($this, 'screen_option'));

image.png
4,在Hzt_Order_Management_Admin_Menu的类中添加如下方法

// 好主题
    public function screen_option()
    {
        $option = 'per_page';
        $args   = array(
            'label'   => 'Customers',
            'default' => 30,
            'option'  => 'customers_per_page'
        );

        add_screen_option($option, $args);

        $this->list_table  = new OrderManagement_List_Table();
    }


    function set_screen($status, $option, $value)
    {
        return $value;
    }

    // 好主题

image.png

4,修改 ‘OrderManagement_List_Table’ 的 prepare_items 方法

$this->_column_headers = $this->get_column_info();
$per_page     = $this->get_items_per_page('customers_per_page', 30);

image.png
5,修改文件’order-list.php’

if (isset($this->list_table)) {
            $this->list_table->prepare_items();
            $this->list_table->search_box('search', 'search_id');
            $this->list_table->display();
        }

image.png