Skip to content

Instantly share code, notes, and snippets.

View CristianoMZN's full-sized avatar

Cristiano Mozena CristianoMZN

  • Marau / RS / Brazil
View GitHub Profile
@alokstha1
alokstha1 / functions.php
Created September 14, 2017 08:13
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 );