CPT UI – Custom taxonomy paginantion – 404 error
-
Hello everybody,
My problem is following: I have created a custom taxonomy (‘osobnosti’) using CPT UI plugin. The taxonomy is supposed to be used as tags for a person. So the writer can tag a person in article and when you visit page /osobnosti/name-of-person it should show the list of articles, where the person is tagged. (I couldn’t use default WP tag for it, because I’m already using it for keyword tags). Everything works fine, but the pagination. When I try to access /osobnosti/name-of-person/page/2 it shows the 404 page not found error. Pagination for tags works well and I’ve tried to replicate it accordingly, however without success.
I’m using WP 4.6 with Voice theme (created child theme). The pagination is used from Voice theme.Code to alter the main query (in child-theme’s functions.php):
function alter_tag_tax_query( $query ) { if(is_tax()) { $tax = get_categories( array( 'slug' => $query->query[key($query->query)], 'taxonomy' => key($query->query), ) ); } if ( ($query->is_tag() || $query->is_tax()) && $query->is_main_query() ) { $query->set('orderby', 'post_date'); $query->set('order', 'DESC'); $query->set('post_status', 'publish'); $query->set('post_type', get_custom_post_types ()); $query->set('posts_per_page', vce_get_option( 'tag_ppp_num' )); if (is_tag()) { $query->set('tag', $query->queried_object->slug); } else if (is_tax()) { $query->set('post__in', get_objects_in_term( $tax[0]->term_id, key($query->query))); } // Get the page number $path = explode('/',$_SERVER['REQUEST_URI']); if (in_array('page', $path)) { $query->set('paged', $path[count($path)-2]); } } } add_action( 'pre_get_posts', 'alter_tag_tax_query' );
The code responsible for populating the content (in child-theme’s index.php):
<?php if (is_tax() || is_tag()) { ?> <?php while ( have_posts() ) : the_post(); ?> <?php get_template_part( 'sections/loops/layout-'.vce_get_archive_layout()); ?> <?php endwhile; ?> <?php } else { get_template_part( 'sections/content-none'); } ?> <?php get_template_part( 'sections/pagination/'.vce_get_archive_pagination()); ?>
I would really appreciate any suggestions. I’ve already read lot of posts about this topic and changed the code accordingly, but nothing helped yet. Before I was using query_posts to fetch the posts from database and thought that if I change that it would solve the problem with pagination as well.
Thank you in advance for any comments. I hope to find a solution with your help.
- The topic ‘CPT UI – Custom taxonomy paginantion – 404 error’ is closed to new replies.