0
Hello!
I know this is probably a repeated question, but as none of the solutions I found around here have managed to solve my problem, I decided to do it anyway.
I’m working on a template with a custom post type. To make the pagination, I used this tutorial here https://medium.com/@bikramkc/wordpress-custom-pagination-functions-php-without-a-plugin-961bc4fb930f
It works perfectly on the Archive of my Cpt, but in the categories of the same, when I change page it returns me a 404.
Follows the code:
// archive.php
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = [
"post_type" => "clientes",
"posts_per_page" => '12',
"paged" => $paged
];
query_posts($args);
if (have_posts()) :
?>
<ul class="customers-section--list">
<?php
while (have_posts()) : the_post(); ?>
[...]
<?php
if (function_exists('custom_pagination')) {
custom_pagination($loop->max_num_pages, "", $paged);
}
endif;
?>
// category.php
<?php
$currCat = get_category(get_query_var('cat'));
$cat_name = $currCat->name;
$cat_id = get_cat_ID( $cat_name );
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = [
"post_type" => "clientes",
"posts_per_page" => '12',
"paged" => $paged,
'category_name' => $cat_name
];
query_posts($args);
if (have_posts()) :
?>
<ul class="customers-section--list">
<?php
while (have_posts()) : the_post();
[...]
<?php
if (function_exists('custom_pagination')) {
custom_pagination($loop->max_num_pages, "", $paged);
}
endif;
Custom post type setup
add_action('init', 'cpt_customers');
function cpt_customers()
{
$labels = [
'name' => 'Clientes',
'singular_name' => 'Cliente'
];
$args = [
'labels' => $labels,
'supports' => ['title', 'editor', 'thumbnail'],
'public' => true,
'menu_icon' => 'dashicons-groups',
'taxonomies' => ['category'],
'has_archive' => true,
];
register_post_type('clientes', $args);
}
I did it! I also needed to make some changes to the permalink menu, but it worked here. Thank you! D
– hugolcouto