Wordpress - Paging does not work in taxonomy

Asked

Viewed 336 times

0

I have a custom post type "news" and a taxonomy "subject" that has its terms, to make the pagination I am using the following code (page-news.php):

$custom_query_args['paged'] = get_query_var( 'paged' ) ? get_query_var( 'paged' ) : 1;
$args = array( 'post_type' => 'noticias', 'paged' => $custom_query_args['paged'], 'posts_per_page' => 5);
$loop = new WP_Query( $args );

$temp_query = $wp_query;
$wp_query   = NULL;
$wp_query   = $loop;

while ( $loop->have_posts() ) : $loop->the_post();
    <!-- Conteúdo aqui -->
endwhile;  

wp_reset_postdata();

if (function_exists("pagination")) {
    pagination($wp_query->max_num_pages);
}

$wp_query = $temp_query;

And the function:

function pagination($pages = '', $range = 4) {  
        $showitems = ($range * 2)+1;  

        global $paged;
        if(empty($paged)) $paged = 1;

        if($pages == '') {
            global $wp_query;
            $pages = $wp_query->max_num_pages;

            if(!$pages) {
                $pages = 1;
            }
        }   

        if(1 != $pages) {
            echo "<div class=\"pagination\"><span>Página ".$paged." de ".$pages."</span>";
            if($paged > 2 && $paged > $range+1 && $showitems < $pages) echo "<a href='".get_pagenum_link(1)."'>&laquo; Primeira</a>";
            if($paged > 1 && $showitems < $pages) echo "<a href='".get_pagenum_link($paged - 1)."'>&lsaquo; Anterior</a>";

            for ($i=1; $i <= $pages; $i++) {
                if (1 != $pages &&( !($i >= $paged+$range+1 || $i <= $paged-$range-1) || $pages <= $showitems )) {
                    echo ($paged == $i)? "<span class=\"current\">".$i."</span>":"<a href='".get_pagenum_link($i)."' class=\"inactive\">".$i."</a>";
                }
            }

            if ($paged < $pages && $showitems < $pages) echo "<a href=\"".get_pagenum_link($paged + 1)."\">Próxima &rsaquo;</a>";  
            if ($paged < $pages-1 &&  $paged+$range-1 < $pages && $showitems < $pages) echo "<a href='".get_pagenum_link($pages)."'>Última &raquo;</a>";
            echo "</div>\n";
        }
    }

Everything works normally on the blog page (page-blog.php), but when I enter a category (taxonomy-subject.php), the pagination appears, but the result is a 404.

The URL that works is: www.example.com/blog/page/2 (which would be the custom post type) Does not work: www.example.com/assunto/page/2 (that would be taxonomy)

I tried several solutions and nothing worked, anyone has any idea?

  • Have you seen if the documentation can help solve your problem? https://codex.wordpress.org/pt-br:Taxonomies

  • I’ve read yes, I haven’t found anything to help me, I’ve tried to flush the permalinks and nothing.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.