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 have created a custom taxonomy for a custom post type called "portfolio" like so:

function jvs_portfolio_categories_init() {
    register_taxonomy(
        'project-category',
        'portfolio',
        array(
      'label'        => __( 'Project Categories' ),
      'query_var'    => true,
      'hierarchical' => true
        )
    );
}
add_action( 'init', 'jvs_portfolio_categories_init' );

Then I added an archives.php page so I could show posts in those taxnomies, the problem is that pagination breaks on the second page, this is basically my loop in the archives page:

<?php $paged = (get_query_var('page')) ? get_query_var('page') : 1; ?>
<?php global $query_string; query_posts($query_string . '&post_type=portfolio&paged=' . $paged); ?>
<?php if (have_posts()) while (have_posts()) : the_post(); ?>
     // Stuff here
<?php endwhile; ?> 

It just shows me a 404 page error when I try to go to the 2nd page, I'm using pretty permalinks but if I manually replace the /page/2 param in the url with ?page=2 it works fine even though the pagination works fine everywhere else in the site.

Can you guys help me? Thanks in advance!

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

This function fixed the issue:

function change_posttype() {
  if( is_archive() && !is_admin() ) {
    set_query_var( 'post_type', array( 'post', 'portfolio' ) );
  }
  return;
}
add_action( 'parse_query', 'change_posttype' );

Then I just removed the paged and query_string function in my code and just left the regular loop :)

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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