Pagination throws 404 error on custom taxonomy archive pages

I have created a custom taxonomy for a custom post type called "portfolio" like so:function jvs_portfolio_cate

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!

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 asked Mar 16, 2012 at 5:09 Javier VillanuevaJavier Villanueva 3,4996 gold badges40 silver badges41 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 5

This function fixed the issue:

function change_posttype() {
  if( is_archive() && !is_admin() ) {
    set_query_var( 'post_type', array( 'post', 'portfolio' ) );
  }
}
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 :)

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745151042a4613869.html

相关推荐

  • Pagination throws 404 error on custom taxonomy archive pages

    I have created a custom taxonomy for a custom post type called "portfolio" like so:function jvs_portfolio_cate

    3小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信