Custom Taxonomy not working with posts_per_page in new WP_query (pagination problem)

OK, so i’m messing with Custom Taxonomies for the second time and in both instances i’ve run into this problem where using the posts_per_page argument in either a query_posts or WP_query scenario.. basically, if i set a custom limit on posts per page, clicking the “next” or “previous” buttons give me 404 errors .. doesnt matter if i use a custom permalink structure or any of the defaults, same result. the only way ive successfully managed to control number of posts on a page is through the Reading Settings in the Dashboard.

i’ve found quite a few mentions of this same problem but have yet to find a working solution aside from above mentioned Dashboard settings:

Read More

wordpress.org/support/topic/custom-taxonomy-navigation-problem-paged1-works-paged2-doesnt?replies=8#post-2093828

core.trac.wordpress.org/ticket/16168

wordpress.org/support/topic/custom-taxonomies-with-pagination-getting-404-page-not-found?replies=6#post-2093414

so, here’s the site im working on with the problem:

http://www.purekreation.com
(click on any of the sections in the nav and then try to navigate to previous pages at the bottom)

and here’s my current (non-working) code:

    <?php get_header(); ?>

    <div id="art">

        <?php global $query_string, $paged, $wp_query, $wp;
        $count = 0;
        $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
        echo $paged;
        ?>
        <?php $term = get_query_var('term'); echo $term;?>
        <?php $tax = get_query_var('taxonomy'); echo $tax;?>
        <?php
        $taxquery=new WP_Query(array('tax_query'=>array(array('taxonomy'=>$tax,'field'=>'slug','terms'=>$term)),'post_type'=>'art','showposts'=>1,'paged'=>$paged));
        while ( $taxquery->have_posts() ) : $taxquery->the_post(); ?>

    <?php $genre = wp_get_post_terms($post->ID, 'genre');?>
        <div id="post-<?php the_ID(); ?>" <?php post_class('post-'.$genre[0]->slug.' post-art');?>> 
            <h3 class="work-title"><?php the_title();?></h3>
            <?php get_the_10(); ?>
            <div class="the-content">
                <?php the_content(); ?>
            </div>
            <footer class="COL-10 clear">
                <small class="post-meta"><?php $terms = get_the_term_list( $post->ID, 'genre', 'Portfolio: ', ' ', '' );  echo $terms;?></small>
                <small class="post-meta">Project: <?php the_tags( '',', ','');?></small>
                <small class="post-meta">Client: <?php $meta = get_post_meta($post->ID, 'client', true); if($meta==''){echo 'Self';}else{echo $meta;}?></small>
                <small class="post-meta right"><a href="#masthead">Back to top</a></small>
                <div class="dash"></div>
            </footer>
        </div><!-- #post-## -->    
        <?php $count++; ?>
        <?php endwhile; ?>
                        <div id="nav-below" class="pagination">
        <?php if($taxquery->max_num_pages>1){?>
            <?php
            for($i=1;$i<=$taxquery->max_num_pages;$i++){?>
                    <a href="<?php bloginfo('url');?>/?<?php echo $tax;?>=<?php echo $term;?>&<?php echo 'paged=' . $i; ?>" <?php echo ($paged==$i)? 'class="selected"':'';?>><?php echo $i;?></a>
                    <?php
            }
            if($paged!=$taxquery->max_num_pages){?>
                    <a href="<?php bloginfo('url');?>/?<?php echo $tax;?>=<?php echo $term;?>&<?php echo 'paged=' . $i; //next link ?>">></a>
            <?php } ?>
    <?php } ?>
                        </div>
            <?php // Reset Post Data
            wp_reset_postdata();
             // End the loop. Whew.?>
    </div><!-- end #art -->
    <?php get_footer(); ?>

im not the most skilled PHP guy but i know a decent amount about WordPress and this problem has me literally losing sleep over it. if anyone has some input on this matter, it’d be GREATLY appreciated.

Related posts

Leave a Reply

1 comment

  1. should it be..

    $paged = (get_query_var('page')) ? get_query_var('page') : 1;
    

    WP_Query in codex:

    Pagination Note: You should set get_query_var( ‘page’ ); if you want your query to work with pagination. Since WordPress 3.0.2, you do get_query_var( ‘page’ ) instead of get_query_var( ‘paged’ ). The pagination parameter ‘paged’ for WP_Query() remains the same.