Skip to content

Instantly share code, notes, and snippets.

View bangbuiduc's full-sized avatar

Bùi Bằng bangbuiduc

View GitHub Profile
@bangbuiduc
bangbuiduc / functions.php
Created July 5, 2021 03:46 — forked from alokstha1/functions.php
WordPress custom pagination with $wpdb->get_results
<?php
$items_per_page = 2;
$page = isset( $_GET['cpage'] ) ? abs( (int) $_GET['cpage'] ) : 1;
$offset = ( $page * $items_per_page ) - $items_per_page;
$query = 'SELECT * FROM '.$table_name;
$total_query = "SELECT COUNT(1) FROM (${query}) AS combined_table";
$total = $wpdb->get_var( $total_query );