我试图在元框中显示WP\\U List\\U表。metabox用于列出课程的注册用户(StreetLMS课程帖子类型)。表格列包含user\\u id、user\\u name、percentage&;等级。我不认为这是一个事实,我正试图为一个自定义的帖子类型。我只是为了清楚起见才提到。
现在的情况是,在我单击自定义帖子类型编辑屏幕上的“按Id搜索”(使用的wp搜索按钮功能)按钮之前,一切看起来都很好。WP\\u List\\u表将重定向回/WP admin/edit。php页面上单击搜索按钮(在输入元素中输入ID后)。它会在编辑屏幕的顶部显示更新后的帖子管理通知。它应该做的是只列出管理员搜索过的用户。我在其他管理菜单页面上使用的相同代码运行良好。所有其他功能都工作正常(升序、降序、order\\u by)。只有搜索功能出现问题。代码附在下面。数据
/** Class constructor */
public function __construct() {
parent::__construct( [
\'singular\' => __( \'Student\', WOOSUB_TEXT_DOMAIN ), //singular name of the listed records
\'plural\' => __( \'Students\', WOOSUB_TEXT_DOMAIN ), //plural name of the listed records
\'ajax\' => false //does this table support ajax?
] );
}
/**
* Function to filter data based on order , order_by & searched items
*
* @param string $orderby
* @param string $order
* @param string $search_term
* @return array $users_array()
*/
public function list_table_data_fun( $orderby=\'\', $order=\'\' , $search_term=\'\' ) {
$users_array = array();
$args = array();
if( !empty( $search_term ) ) {
$searchcol= array(
\'ID\',
\'user_email\',
\'user_login\',
\'user_nicename\',
\'user_url\',
\'display_name\'
);
$args = array(
\'fields\' => \'all_with_meta\',
\'orderby\' => $orderby ,
\'order\' => $order ,
\'search\' => $_REQUEST["s"] ,
\'search_columns\' => $searchcol
);
} else {
if( $order == "asc" && $orderby == "id" ) {
$args = array(
\'orderby\' => \'ID\',
\'order\' => \'ASC\',
);
} elseif ( $order == "desc" && $orderby == "id" ) {
$args = array(
\'orderby\' => \'ID\',
\'order\' => \'DESC\',
);
} elseif ( $order == "desc" && $orderby == "title" ) {
$args = array(
\'orderby\' => \'name\',
\'order\' => \'DESC\',
);
} elseif ( $order == "asc" && $orderby == "title" ) {
$args = array(
\'orderby\' => \'name\',
\'order\' => \'ASC\',
);
} else {
$args = array(
\'orderby\' => \'ID\',
\'order\' => \'DESC\',
);
}
}
$users = get_users( $args );
if( count( $users ) > 0 ) {
foreach ( $users as $index => $user) {
$author_info = get_userdata( $user->ID );
if ( $user ) {
$users_array[] = array(
"id" => $user->ID,
"title" => \'<b><a href="\' .get_author_posts_url( $user->ID ). \'"> \'. $author_info->display_name .\'</a></b>\' ,
"percentage" => 10,
"grade" => \'<label style="color:\'.\'black\'.\';"><b>\'. \'A\'.\'</b><label>\'
);
}
# code...
}
}
return $users_array;
}
//prepare_items
public function prepare_items() {
$orderby = isset( $_GET[\'orderby\'] ) ? trim( $_GET[\'orderby\'] ): "";
$order = isset( $_GET[\'order\'] ) ? trim( $_GET[\'order\'] ) : "";
$search_term = isset( $_POST[\'s\'] ) ? trim( $_POST[\'s\'] ) : "";
if( $search_term == "" ) {
$search_term = isset( $_GET[\'s\'] ) ? trim( $_GET[\'s\'] ) : "";
}
$datas = $this->list_table_data_fun( $orderby, $order, $search_term );
$per_page = 3;
$current_page = $this->get_pagenum();
$total_items = count($datas);
$this->set_pagination_args( array( "total_items"=> $total_items,
"per_page" => $per_page ) );
$this->items = array_slice( $datas, ( ( $current_page - 1 )* $per_page ), $per_page );
$columns = $this->get_columns();
$hidden = $this->get_hidden_columns();
$sortable = $this->get_sortable_columns();
$this->_column_headers = array( $columns, $hidden, $sortable );
}
//get_columns
public function get_columns() {
$columns = array(
"cb" => "<input type=\'checkbox\'/>",
"id" => "ID",
"title" => "User Name",
"percentage" => "Percentage",
"grade" => "Grade",
"action" => "Action"
);
return $columns;
}
public function get_hidden_columns() {
return array("");
}
public function get_sortable_columns() {
return array (
"title" => array( "title", true ),
"id" => array( "id", true ),
);
}
//column_default
public function column_default( $item, $column_name ){
switch ( $column_name ) {
case \'id\':
case \'title\':
case \'percentage\':
case \'grade\':
return $item[ $column_name ];
case \'action\':
if ( isset ( $_GET[\'page\'] ) ){
$page = $_GET[\'page\'];
} else {
global $pagenow;
$page = $pagenow;
}
return \'<a href="?page=\'.$page.\'&action=llmsgb-edit&user_id=\'.$item[\'id\'].\'">Edit</a>\';
default:
return "no value";
}
}
protected function display_tablenav( $which ) {
// REMOVED NONCE -- INTERFERING WITH SAVING POSTS ON METABOXES
// Add better detection if this class is used on meta box or not.
// if ( \'top\' == $which ) {
// wp_nonce_field( \'bulk-\' . $this->_args[\'plural\'] );
// }
}
public function column_title( $item ) {
if ( isset ( $_GET[\'page\'] ) ){
$page = $_GET[\'page\'];
} else {
global $pagenow;
$page = $pagenow;
}
$action = array(
"edit" => sprintf(\'<a href="?page=%s&action=%s&user_id=%s">Edit</a>\',$page,\'llmsgb-edit\',$item[\'id\']));
return sprintf(\'%1$s %2$s\', $item[\'title\'],$this->row_actions( $action ) );
}
}
功能列表\\u table\\u布局(){
$myRequestTable=新列表\\u表\\u类();
global $pagenow;
?>
<div class="wrap"><h2>Students Grades Information</h2>
<form method="get">
<input type="hidden" name="page" value="<?php echo $pagenow ?>" />
<?php if( isset( $myRequestTable ) ) : ?>
<?php $myRequestTable->prepare_items(); ?>
<?php $myRequestTable->search_box( __( \'Search Students By ID\' ), \'students\' ); //Needs To be called after $myRequestTable->prepare_items() ?>
<?php $myRequestTable->display(); ?>
}list\\u table\\u layout();