-2

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(); ?>
2
  • 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, 2012 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, 2012 at 17:21

2 Answers 2

0
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!

0

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' ) );      
        }
1
  • I still would like to use it so it matches the rest of the site
    – Tallboy
    Mar 25, 2012 at 16:37

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