Using WP_List_Table and search_box(): How to Paginate the Found Search Results When Sending by Method «Post»?
I am using a custom WP_List_Table-Class in order to display a custom table with hotels in the dashboard. I can skip through the pages with the pagination on the top right as expected.
The search form is also added with
$my_list_table_instance-search_box( 'Search', 'search_id' );
and it is working fine, but only for the first page.
Inside the form, I have the two hidden fields for the pagination:
// List and form output
$page = filter_input( INPUT_GET, 'page', FILTER_SANITIZE_STRIPPED );
$paged = filter_input( INPUT_GET, 'paged', FILTER_SANITIZE_NUMBER_INT );
echo 'form method="post" id="list-hotels-form"';
printf( 'input type="hidden" name="page" value="%s" /', $page );
printf( 'input type="hidden" name="paged" value="%d" /', $paged );
$hotel_table-prepare_items();
$hotel_table-search_box( __( 'Search Hotels', 'uruk' ), 'search_id' );
$hotel_table-display();
echo '/form';
// ...
The Problem
When sending the search form by post method, I do not get a (unaesthetically) long query string. The search terms are inserted into the search form again, but they are not appended to the pagination links. So when skipping to the following page of results, I lose the search terms.
My Question(s)
- How can I add a query argument to the pagination links when a search
term is present? The method
set_pagination_args()
does not allow to append custom arguments to the pagination links. - Better send the form by get (as recommanded here) from the beginning and rebuilding the form action-value from the ground? Otherwise the action-value is getting much too long, since the referrer is appended each time.
Topic wp-list-table pagination Wordpress
Category Web