I'm trying to make a custom PHP pagination work with wordpress, the page in wordpress is a very custom one, not a post or a page, it's a select from DB that shows flowers, the styling is ok now, but it shows all the flowers in a city and i want to limit 10 flowers per page:
$per_page = 10;
$page = (isset($_GET['page'])) ? (int)$_GET['page'] : 1;
$startAt = $per_page * ($page - 1);
$user_query_subs = new WP_User_Query( array('meta_key' => 'location', 'number' => $per_page, 'offset' => $startAt, 'meta_value' => $flow_location, 'meta_compare' => '=', 'role' => 'admin', 'orderby' => 'rand', 'order' => 'DESC'), array('fields' => 'all_with_meta') );
$all_user_query_subs = new WP_User_Query( array('meta_key' => 'location', 'meta_value' => $flow_location, 'meta_compare' => '=', 'role' => 'admin', 'orderby' => 'rand', 'order' => 'DESC'), array('fields' => 'all_with_meta') );
$all_flowers = $all_user_query_subs->get_total();
$flowers = $user_query_subs->get_results();
and after the content is loaded: i'm adding the links on the bottom like this:
<?php
$totalPages = $all_flowers / $per_page;
$links = "";
$current_url = "http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
for ($i = 1; $i <= $totalPages; $i++) {
$links .= ($i != $page )
? "<a href='" . "$current_url" . "page/$i/'>Page $i</a> "
: "$page ";
}
echo $links;
?>
The select query is working perfectly, it's loading only 10 per page, but my problem is with the links at the bottom:
Right now when i press the page 2 to access the next 10 flowers from the city, i get Page Not Found from Wordpress but with the correct $current_url/page/$i
Any ideas please? Thanks in advance!