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.

Pagination for a custom post type in category.php returns a 404 page for /page/2. If I go to /page/1 it redirects and works fine, but /page/2 breaks.

Permalinks are set to /%postname%/

I've tried all the fixes I have seen on google, but nothing works

<?php
get_header(); ?>

<div class="home-gradient">
<div id="container">

    <?php include('snippet-post-gallery.php'); ?>




<div class="content-wrap">  

    <?php 

       $catID = get_query_var('cat');
       $catName = strtolower(get_cat_name($catID));


      $myquery = new WP_Query(array(
            'post_type' => 'any',
                'paged' => $paged,
                'posts_per_page' => 1,
          'category_name' => $catName)
            );

        while ( $myquery->have_posts() ) : $myquery->the_post(); 


            $img_id = get_post_meta($post->ID,'main_image',true);
            $img_url = wp_get_attachment_url($img_id);

        ?>


            <div class="post-box">
    .............
            </div>



        <?php

      endwhile;
       wp_pagenavi( array( 'query' => $myquery ) );
       ?>

    <?php ?>


    </div>

        <div class="sidebar-wrap">
            <?php get_sidebar(); ?>
        </div>

        <br class="clear">
    </div>
    </div>

    <?php get_footer(); ?>
share|improve this question
    
By the way if a mod can make this eligible for bounty now I'll give up all 115 points that i have. –  Tallboy Mar 25 '12 at 16:35
    
Please try to give this meaningful title. I get that this is frustrating for you, but non-descriptive title doesn't help to get it answered. –  Rarst Mar 25 '12 at 17:21

2 Answers 2

Instead of wp_pagenavi( array( 'query' => $myquery ) ); use the following code if you do not want to display pagintion using pagenavi.

if ( get_next_posts_link() || get_previous_posts_link() ) { 
           next_posts_link( __( '&larr; Older Entries', 'rtPanel' ) );
         previous_posts_link( __( 'Newer Entries &rarr;', 'rtPanel' ) );      
        }
share|improve this answer
    
I still would like to use it so it matches the rest of the site –  Tallboy Mar 25 '12 at 16:37
up vote 0 down vote accepted
function category_set_post_types( $query ){
    if( $query->is_category ):
        $query->set( 'post_type', 'any' );
    endif;
    return $query;
}
add_action( 'pre_get_posts', 'category_set_post_types' );

This worked!

share|improve this answer

protected by Community Jun 25 at 7:42

Thank you for your interest in this question. Because it has attracted low-quality answers, posting an answer now requires 10 reputation on this site.

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.