Home > database >  wordpress admin panel get parameter
wordpress admin panel get parameter

Time:12-13

I'm developing a plugin in wordpress, there is data that needs to be listed by search but I can't get them with the get parameter.

I can send with the post parameter, but when the user refreshes the page, she has to search again according to the order number.

Following my code:functions.php

add_action('admin_menu', 'testPluginAdminMenu');

function testPluginAdminMenu()
{
     add_menu_page('Return Request',
        'Return Request',
        'manage_options',
        'list',
        'myFunction'
        );
     add_submenu_page(
        'null',
        'Return Request List',
        'Return Request List',
        'manage_options',
        'listAll',
        'myFunctionList');

}

index.php

<?php
function myFunctionList(){ 
 if(isset($_GET['request_order'])){
 echo $search = $_GET['request_order'];
 }
}
function myFunction(){ ?>

<form method="get" action="<?php echo admin_url('admin.php?page=listAll&request_order='.$_GET['request_order'] ) ?>">
  <input type="text" name="request_order" placeholder="Search Order Number..">
  <button type="submit" >Search</button>
</form>

<?php } ?>

Output from url: localhost/wordpress/wp-admin/admin.php?request_order=7481

page=listAll not appearing on url

Thank you advance.

CodePudding user response:

Can you try something like this

$qs = array(
    'page' => 'listAll',
    'request_order' => $_GET['request_order']
);

$qs = http_build_query($qs, null, "&", PHP_QUERY_RFC3986);
<?php echo admin_url('admin.php?' . $qs ) ?>

UPDATE 1

<form method="get" action="<?php echo admin_url('admin.php?page=listAll&request_order='.$_GET['request_order'] ) ?>">
  <input type="text" name="request_order" placeholder="Search Order Number..">
  <input type="hidden" name="page" value="listAll" />
  <button type="submit" >Search</button>
</form>
  • Related