Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I've created list of custom taxonomy term and have problem with pagination.

Custom post type "gallery" has his own custom taxonomy "gallery_category". The next loop lists all items of chosen Gallery category:

        /* Some info:
         * http://wordpress.stackexchange.com/questions/13888/retrieve-single-term-slug
         * http://codex.wordpress.org/Function_Reference/WP_Query#Taxonomy_Parameters
         */
        $term_slug = get_queried_object()->slug;
        if ( !$term_slug )
            return;
            else
        $args = array(
            'tax_query' => array(
                array(
                    'post_type' => 'gallery',
                    'taxonomy' => 'gallery_category',
                    'field' => 'slug',
                    'terms' => $term_slug
                )
            ), 
            'posts_per_page' => 3,
            'paged' => get_query_var( 'paged' )
        );
        $loop = new WP_Query( $args );
            while ( $loop->have_posts() ) : $loop->the_post(); ?>

            <div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
                <h2 class="entry-title"><a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'poznaj-wilno' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><?php the_title(); ?></a></h2>
                <div class="entry-thumbnail">
                    <?php if ( has_post_thumbnail() ) : ?>
                        <a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'poznaj-wilno' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><?php the_post_thumbnail( 'gallery-thumbnail' ); ?></a>
                    <?php endif; ?>
                </div><!-- .entry-thumbnail -->         
            </div><!-- #post-## -->             
            <?php endwhile; // End the loop. Whew.
/*Using WP-PageNavi plugin. 
* Call based on - http://scribu.net/wordpress/wp-pagenavi/wpn-2-74.html
*/ ?>
<div class="pagination">
<?php
    if ( function_exists('wp_pagenavi') )
 wp_pagenavi( array( 'query' => $loop ) ); 
?>
</div><!-- .pagination -->    

I'm using WP PageNavi plugin to create pagination and I'm facing the problem with "get_queried_object()" function.

It takes term name from the link: http://domain.ltd/gallery/categories/term-slug.

When I click on next page, link changes to: ../gallery/categories/term-slug/page/2. Because link slug has been changed I'm getting an error.

Maybe you have any ideas how could i solve this problem? Thanks.

share|improve this question
    
What's the error you get? –  Bainternet Jun 5 '11 at 11:32
    
I'm getting 404 Page not found error. PHP error log shows nothing, apache too. –  Andrew Jun 6 '11 at 13:36
    
I followed conversation on wpquestions.com/question/show/id/710 & have tried their suggestion to set "Blog pages show at most" in "Settings/Reading" from default 10 to 1. And it solved the problem. Now my loop works great. I could not understand why this setting influences my query. Because I'm setting my own value posts_per_page value in the loop. Maybe it's a bug and I should post it on trac? –  Andrew Jun 8 '11 at 13:53
add comment

closed as too localized by toscho Jul 5 '12 at 21:11

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.If this question can be reworded to fit the rules in the help center, please edit the question.