WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

get_header(); ?>

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

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

<div class="content-wrap">  


       $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">


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

    <?php ?>


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

        <br class="clear">

    <?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
up vote 0 down vote accepted
function category_set_post_types( $query ){
    if( $query->is_category ):
        $query->set( 'post_type', 'any' );
    return $query;
add_action( 'pre_get_posts', 'category_set_post_types' );

This worked!

share|improve this answer

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

protected by Community Jun 25 '14 at 7:42

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

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.