I created a custom post type with taxonomies. I created an archive page with the list of all taxonomies used in this CPT.
My problem
After a lot of research on different tutorials, I can't get the pagination to work. The pagination appears well, but when I click on the second page I arrive at a 404 page.
I specify that I must do this by a shortcode that I must include in a theme
I would like to specify in the wordpress settings I have specified the number of post / page to 9, the same in the theme
Here is my code
$paged = get_query_var('paged') ? get_query_var('paged') : 1;
$per_page = 9;
$total = count(get_terms('job_taxo'));
$offset = (($paged - 1) * $per_page);
$jobs = get_terms(array(
'taxonomy' => 'job_taxo',
'orderby' => 'term_order',
'number' => $per_page,
'offset' => $offset,
));
foreach($jobs as $job){
<a href="'. esc_url(#) .'">'. $job->name .'</a>
}
$big = 99999;
echo paginate_links (array(
'base' => str_replace($big, '%#%', esc_url(get_pagenum_link($big))),
'format' => '?paged=%#%',
'current' => $paged,
'total' => ceil($total / $per_page)
));
CodePudding user response:
Can you check your custom taxonomies are linked with custom posts, because i think your posts are not properly linked with custom taxomnomy thats why you are getting this error, please check count in taxonomy, wp backend and if you see count is equal to number of posts you are getting in front end then only pagination will work