I would like to have a pagination on a page where multiple custom post are listed. For my query, I am not using the usual wp_query with args, I am using a custom database select
Here is my query
$query = "SELECT distinct($wpdb->posts.id), omvp_posts.* FROM $wpdb->posts
inner JOIN $wpdb->postmeta AS rating ON( $wpdb->posts.ID = rating.post_id AND rating.meta_key = 'omvp_vote_rating')
inner JOIN $wpdb->postmeta AS vote ON( $wpdb->posts.ID = vote.post_id AND vote.meta_key = 'omvp_total_vote')
inner JOIN $wpdb->term_relationships ON ( $wpdb->posts.ID = $wpdb->term_relationships.object_id )
WHERE $wpdb->posts.post_status = 'publish'
AND $wpdb->posts.post_type = 'guides'
" . $CategoryQuery . "
ORDER BY rating.meta_value, vote.meta_value DESC LIMIT 0,5";
It's returning my posts, with the order I want, and I only get 5 of them
To loop trought my result, I use this code:
$pageposts = $wpdb->get_results($query, object);
if ($pageposts):
global $post;
foreach ($pageposts as $post):
setup_postdata($post);
For my navigation, I was previously using this function, but I think since I am using a custom query, this function dosen't work anymore
function wp_numeric_pagination() {
global $wp_query;
$big = 999999999;
$search_for = array( $big, '#038;' );
$replace_with = array( '%#%', '' );
$tag = '<div class="pagination">' . PHP_EOL;
$tag .= paginate_links( array(
'base' => str_replace( $search_for, $replace_with, esc_url( get_pagenum_link( $big ) ) ),
'format' => '?paged=%#%',
'current' => max( 1, get_query_var('paged') ),
'total' => $wp_query->max_num_pages,
'prev_next' => True,
'prev_text' => __('«'),
'next_text' => __('»'),
'before_page_number' => '<span>',
'after_page_number' => '</span>'
) ) . PHP_EOL;
$tag .= '</div>' . PHP_EOL;
echo $tag;
}
Thank you !