wp_pagenavi() with custom wp_query()?

?php
/*
Template Name: Projects
*/
?

?php get_header();?

    section id="content"
        section id="main"

            ?php
                $loop = new WP_Query(array('post_type' = 'projects', 'posts_per_page' = 4));
                $i=1;
                while ( $loop-have_posts() ) : $loop-the_post();
            ?

            article class="post?php if($i%2 == 0) { echo ' right'; }; $i++; ?" id="post-?php the_ID(); ?"
                h2?php the_title(); ?/h2
                section class="entry"
                    ?php the_excerpt(); ?
                /section
            /article

            ?php
                endwhile;
                wp_pagenavi();
            ?

            section id="map"
                img src="?php bloginfo('template_url') ?/images/interactive-map.jpg" alt="Interactive Map" /
            /section
        /section

?php get_sidebar(); ?

    /section

?php get_footer(); ?

I have pagenavi set up right after the endwhile. It's not working, though. Anybody know how I can get this to work?

Topic plugin-wp-pagenavi loop pagination custom-post-types Wordpress

Category Web


<?php       // Pagination
        if(function_exists('wp_pagenavi')) :
            wp_pagenavi( array( 'query' => $blog_posts_query ) );
        else : ?>
            <div class="navigation">
                <div class="alignleft"><?php previous_posts_link() ?></div>
                <div class="alignright"><?php next_posts_link() ?></div>
            </div>
<?php       endif;

                // Restore original Post Data
                wp_reset_postdata(); ?>

wp_pagenavi( array( 'query' => $loop ) );

should work with the code above. Don't hijack the main query if you can avoid it.

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.