Pass additional parameter in the URL

How do I pass additional parameter in the url for pagination to work

my existing page link is http://localhost/site/wp-admin/admin.php?page=myPage

Read More

How do I create the syntax / logic in PHP to add &pagenum=1 in the url?

currently I have this code

global $wpdb;

$per_page = 6;
$page_query = $wpdb->get_var("SELECT COUNT('id') FROM form"); 

$pages = ceil($page_query / $per_page);

$currentPage = (isset ($_GET['pagenum'])) ? (int)$_GET['pagenum'] : 1;
$start = ($currentPage -1 ) * $per_page;

$row = $wpdb->get_results("SELECT * FROM form LIMIT $start , $per_page");

//foreach loop here

Related posts

1 comment

  1. There is a wordpress function for adding $_GET-Params to an URL: add_query_arg(). It works like this:

    $link = add_query_arg( array('pagenum' => $your_page_number) );
    

    By default it adds the param to the current page (gets content from $_SERVER[REQUEST_URI]) but you can also pass an optional param to the function if you want the link to go to another page:

    $link = add_query_arg( array('pagenum' => $your_page_number), $your_page_link);
    

Comments are closed.