I use Plugin Boilerplate for my project. I searched the internet and read all the questions but I couldn’t find what I need. I also read the WordPress Codex. I think I couldn’t get the idea.
I have two columns on my page. Col1 and Col2
Inside col1: wp_list_table
Inside col2: empty
Page address: admin.php?page=company#home
When I clicked the Add New button on wp_list_table
, the address bar shows admin.php?page=company#home&action=new
I want to get the action value from the url. I tried the code below:
function addnew_query_vars($vars) {
$vars[] = 'action';
return $vars;
}
add_filter('query_vars', 'add_query_vars_filter');
echo $value = get_query_var('action'); // Nothing happens
How I can get action value? If I can get the value, I’ll show a form inside the col2 or using a switch statement for other situations.
UPDATE 1.1.0
Using get_current_screen
require_once(ABSPATH . 'wp-admin/includes/screen.php');
$screen = get_current_screen();
echo $screen->action; // Null
I'm using query monitor plugin. I looked Admin Screen status get_current_screen() action is empty. So I need to go back.
In the my WP_List_Table header code, my Add New button code is like this:
<a href="<?php echo admin_url( 'admin.php?page=company#home&action=new' );?>">
php _e( 'Add New', 'ironhead' )
</a>
I think this code block doesn't post the action. There is set_current_screen() command. But I don't solve how to set Admin Screen action attribute. IF I can use it, I can use get_current_screen(). Anyone help me?
ALL CODE
TAB PANE
<ul class="nav nav-tabs nav-pills tab-pane" id="myTab" role="tablist">
<li class="nav-item">
<a class="nav-link active" id="home-tab" data-toggle="tab" href="#home" role="tab" aria-controls="home" aria-selected="true">Company</a>
</li>
<li class="nav-item">
<a class="nav-link" id="facility-tab" data-toggle="tab" href="#facility" role="tab" aria-controls="facility" aria-selected="false">Facility</a>
</li>
...
</ul>
TAB CONTENT
<div class="tab-content" id="myTabContent">
<div class="tab-pane fade show active" id="home" role="tabpanel" aria-labelledby="home-tab">
<div class="row">
<div class="col">
<?php
function wp_get_all_company( $args = array() ) {
global $wpdb;
$defaults = array(
'number' => 20,
'offset' => 0,
'orderby' => 'ID',
'order' => 'ASC',
);
$args = wp_parse_args( $args, $defaults );
$cache_key = 'company-all';
$items = wp_cache_get( $cache_key, 'ironhead' );
if ( false === $items ) {
$items = $wpdb->get_results( 'SELECT * FROM ' . $wpdb->prefix . 'ih_company ORDER BY ' . $args['orderby'] .' ' . $args['order'] .' LIMIT ' . $args['offset'] . ', ' . $args['number'] );
wp_cache_set( $cache_key, $items, 'ironhead' );
}
return $items;
}
function wp_get_company_count() {
global $wpdb;
return (int) $wpdb->get_var( 'SELECT COUNT(*) FROM ' . $wpdb->prefix . 'ih_company' );
}
function wp_get_firma( $id = 0 ) {
global $wpdb;
return $wpdb->get_row( $wpdb->prepare( 'SELECT * FROM ' . $wpdb->prefix . 'ih_company WHERE ID = %d', $id ) );
} ?>
<h4><?php _e( 'Company List', 'ironhead' ); ?> <a href="<?php echo admin_url( 'admin.php?page=company#home&action=new' ); ?>" class="add-new-h2"><?php _e( 'Add New', 'ironhead' ); ?></a></h4>
<form method="post">
<input type="hidden" name="page" value="ttest_list_table">
<?php
$list_table = new Company_List_Table();
$list_table->prepare_items();
$list_table->search_box( 'search', 'search_id' );
$list_table->display();
?>
</form>
</div>
<div class="col">
// action=new (or action=something) if or switch statement will be here.
</div>
</div>
Thanks in advance
#home
coming from? Are you adding that to the page url? IIRC, Anything that comes after the#
is not sent to the server.admin.php?action=new&page=company#home
#
is causing the action to not go to the server. So the#home
needs to be at the end of the query string, so likeadmin.php?action=new&page=company#home
oradmin.php?page=company&action=new#home
. Can you post code of the how the "Add New" button is generated?