WordPress.org

Ready to get started?Download WordPress

Forums

Custom query with WP-PageNavi (6 posts)

  1. serpico
    Member
    Posted 3 years ago #

    Has anyone got any advice for implementing pagination preferrably WP-PageNavi when Displaying Posts Using a Custom Select Query?

    An example of 'The Completed Page Template ' with pagination would be greatly appreciated!

  2. MichaelH
    Member
    Posted 3 years ago #

    You need to use a custom query like to return just the post ids of the desired posts, then use those IDs in a 'post__in' argument with a new WP_Query (see the Pages article for a sample of a query that paginates}.

  3. serpico
    Member
    Posted 3 years ago #

    Maybe I should clarify. This is my custom query. It delivers all the posts from the query on the same page. I want to now use the Page-Navi plugin to paginate the results to 5 per page. Is this possible?

    <?php
    		$querystr = "SELECT P .  * , PM.meta_value as Default_Order
    FROM wp_posts P, wp_postmeta PM, wp_term_relationships PC
    WHERE P.ID = PM.post_id
    AND PM.meta_key = 'Display_Order'
    AND P.post_status = 'publish'
    AND P.post_type = 'post'
    
    AND PC.object_id = P.ID
    AND PC.term_taxonomy_id = 9
    
    AND exists (
    	SELECT *
    	FROM wp_postmeta DPM
    	WHERE P.ID = DPM.post_id
    	AND DPM.meta_key = 'Suburb'
    	AND DPM.meta_value = 'Sunshine Beach'
    )
    ORDER BY Default_Order+1 ASC";
    
    	 	$pageposts = $wpdb->get_results($querystr, OBJECT);
    
    		 ?>
    
    		<?php if ($pageposts): ?>
    			<?php foreach ($pageposts as $post): ?>
    			<?php setup_postdata($post); ?>
    
    			<div id="post_feed">
    				<a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>">
    				<?php the_excerpt(); ?>
    			</div>  
    
    			<?php  endforeach; ?>	
    
    			<div class="pagenavi">
    				<?php if (function_exists('wp_pagenavi')) { ?><?php wp_pagenavi(); ?><?php } ?>
    			</div>    
    
    		<?php else : ?>
    			<div class="post">
    				<h2><?php _e('No properties have been found. Please try again.'); ?></h2>
    			</div>
    		<?php endif; ?>
  4. serpico
    Member
    Posted 3 years ago #

    From what I understand, this can't be done. I gather you have to write your own pagination script. I found this WP pagination help useful.

  5. alivethemes
    Member
    Posted 3 years ago #

    Sure it can be done. Run this before the loop:
    <?php query_posts(array('category__not_in' => array(29,30,31), 'paged' => (get_query_var('paged')) ? get_query_var('paged') : 1)); ?>

  6. jenwrigh
    Member
    Posted 3 years ago #

    Hello,

    I am having a problem with custom queries and the WP-PageNavi plugin. The PageNavi is paging some of my posts but not all of them. For instance, for one custom query by state, I have 1,300 posts and only about 190 of them are getting paged under the custom search query. I will appreciate any help and will happy to compensate anyone that can help me solve this problem! Thank you!

    edit: code removed as per the forum guidelines, please use http://wordpress.pastebin.ca

Topic Closed

This topic has been closed to new replies.

About this Topic