I have a category template which holds a query to custom post with a category. The strange thing is when the pagination loads it displays how many pages we have. But when I click on the second page of the pagination it gives me a 404 page.
If I make the query only to fetch the custom post or to fetch the category it works fine. After I have refresh the query with the test for the custom post and the category it works fine. Here is the code of the category template:
<div id="conteiner-first-vision">
<section id="inner-pad">
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array(
'posts_per_page' => 6,
'post_type' => 'awards-pub',
'cat'=>6,
'paged' => $paged,
'order'=>'DESC'
);
$wp_query = new WP_Query( $args );
//wp_query->query('showposts=5'.'&paged='.$paged);
$i=1;
while ( $wp_query->have_posts() )
{
$wp_query->the_post();
?>
<article class="article-first-vision <?= ($i==2)?'mar':'' ?>" >
<?php if ( has_post_thumbnail()) { ?>
<a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>">
<?php the_post_thumbnail('menu-pub'); ?>
</a>
<?php
}; ?>
<h2>
<?php the_title(); ?>
</h2>
<div class="article-description">
<?= truncateHtml(get_the_content()); ?>
</div>
<a href="<?php the_permalink(); ?>" style="bottom:0; right:0;" class="pa"><img src="<?php bloginfo('template_url') ?>/img/link-articles.png"></a> </article>
<?php
if($i==3){$i=0;}
$i++;
}
?>
</section>
<div class="clear"></div>
<div class="pagination-conteiner">
<?php
get_template_part('pagination');
?>
</div>
<div class="clear"></div>
<?php
wp_reset_query();
?>
And this is the pagination:
global $wp_query;
$big = 999999999;
echo paginate_links(array(
'base' => str_replace($big, '%#%', get_pagenum_link($big)),
'format' => '?paged=%#%',
'current' => max(1, get_query_var('paged')),
'total' => $wp_query->max_num_pages,
'prev_next' => True,
'prev_text' => __('«'),
'next_text' => __('»'),
));
And this is the custom post:
register_post_type('awards-pub', // Register Custom Post Type
array(
'labels' => array(
'name' => __('Awards', 'awardspub'), // Rename these to suit
'singular_name' => __('Awards Post', 'awardspub'),
'add_new' => __('Add Awards', 'awardspub'),
'add_new_item' => __('Add Awards Post', 'awardspub'),
'edit' => __('Edit', 'awardspub'),
'edit_item' => __('Edit Awards Post', 'awardspub'),
'new_item' => __('New Awards Post', 'awardspub'),
'view' => __('View Awards Post', 'awardspub'),
'view_item' => __('View Awards Post', 'awardspub'),
'search_items' => __('Search Awards Post', 'awardspub'),
'not_found' => __('No Awards Posts found', 'awardspub'),
'not_found_in_trash' => __('No Awards Posts found in Trash', 'awardspub')
),
'public' => true,
'hierarchical' => true, // Allows your posts to behave like Hierarchy Pages
'has_archive' => true,
'supports' => array(
'title',
'editor',
'excerpt',
'comments',
'thumbnail'
), // Go to Dashboard Custom HTML5 Blank post for supports
'can_export' => true, // Allows export in Tools > Export
'taxonomies' => array(
'post_tag',
'category'
) // Add Category and Post Tags support
));
And to add the category to the custom post:
register_taxonomy_for_object_type('category', 'awards-pub');
register_taxonomy_for_object_type('post_tag', 'awards-pub');