I know how to display the WordPress database table with Foreach loop, but I want to add pagination to the output HTML table so that it should show only the first 100 results then I can use pagination options for further output (if I can use something like $xrd_match = $wpdb->get_results ( "SELECT * FROM xrd_data_match LIMIT $next, 10" );).

global $wpdb;
$xrd_match = $wpdb->get_results ( "SELECT * FROM xrd_data_match" );
foreach ( $xrd_match as $print )   {
<td><?php echo $print->order_id;?></td>
<td><?php echo $print->match1;?></td>
<?php }
  • Check this question, not sure why you run a sql query instead of using the built in functions/classes to get DB data. I would suggest reading about those first before you start running sql queries Apr 4, 2022 at 7:05
  • Sir, will this default wordpress fucntion paginate_links() work for custom wordpress database table, because this is not a post table? Apr 4, 2022 at 7:13
  • If you plan on using a custom DB table you would need to create your own pagination. My question is why create a custom table in the first place? using custom post types/taxonomies cannot give you the solution you are looking for? You could also use ACF to add adittional input fields to add as much custom data as you need Apr 4, 2022 at 7:16
  • Sir, this is no way related to posts. This is some custom WordPress database table created for woocommerce orders custom data. Apr 4, 2022 at 7:24


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.