WordPress.org

Ready to get started?Download WordPress

Forums

WP-PageNavi
Adding Pagination to a Custom Select Query (2 posts)

  1. eggroup
    Member
    Posted 2 years ago #

    I'm using a Custom Select Query to return posts sorted by Custom Field value and it's working but it returns all my 350 posts in one page I need to add a pagination to only show 20 posts per page like the rest of my website.

    I used the exact same code shown in this Codex page :
    http://codex.wordpress.org/Displaying_Posts_Using_a_Custom_Select_Query

    <?php
     $querystr = "
        SELECT $wpdb->posts.*
        FROM $wpdb->posts, $wpdb->postmeta
        WHERE $wpdb->posts.ID = $wpdb->postmeta.post_id
        AND $wpdb->postmeta.meta_key = 'top'
        AND $wpdb->posts.post_status = 'publish'
        AND $wpdb->posts.post_type = 'post'
        AND $wpdb->posts.post_date < NOW()
        ORDER BY ABS($wpdb->postmeta.meta_value) DESC
     ";
     $pageposts = $wpdb->get_results($querystr, OBJECT);
    ?>
     <?php if ($pageposts): ?>
      <?php global $post; ?>
      <?php foreach ($pageposts as $post): ?>
        <?php setup_postdata($post); ?>
    <div id="post-<?php the_ID(); ?>" class="thumbnail" >

    PS: the plugin works perfect on all the rest of my website.

    http://wordpress.org/extend/plugins/wp-pagenavi/

  2. marlonlamancio
    Member
    Posted 2 years ago #

    Maybe this will help you

    http://scribu.net/wordpress/wp-pagenavi/wpn-2-74.html

    Good luck!

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic