This is a bit of a headscratcher.
So, I am using the WP Download Manager Pro plugin that creates a custom post type wpdmpro
.
I have pages for each category, and using the loop, I loop through each post with a post-type
of wpdmpro
.
<?php
$paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1;
$args = array(
'orderby' => 'date',
'order' => 'DESC',
'post_status' => 'publish',
'posts_per_page' => 2,
'paged' => $paged,
'post_type' => 'wpdmpro',
'wpdmcategory' => $category->category_nicename,
'tag' => $cat_tag
);
query_posts($args)
?>
<?php if (have_posts()) : ?>
/* content goes here */
<?php endif; ?>
<?php else : ?>
<div class="row">
<h2 class="center">Not Found</h2>
<p class="center">Sorry, but you are looking for something that isn't here.</p>
<?php get_search_form(); ?>
</div>
<?php endif; ?>
I have a total of 11 posts within a particular category I am testing, so I would expect 6 pages?
Page 1,2 & 3 work fine. However, when I hit /page/4
I am greeted with a 404 page?
Funny thing is, that if I were to change posts_per_page
to let's say 20
, so I would have 1 page. If I were then to go to /page/2
or /page/3
I do not get a 404 page, instead I get the Not found
element with the search form?
Now, at the beginning of this project, I was using the standard Wordpress post type that has a total number of 34
posts. When I bring that post number down to 29
now /page/3
Doesn't work, so, somehow, the pagination is still linked to the old post type and the posts that still currently reside there and I have no idea where this may be linked up?
Trying with 'post_type' => 'post',
does render the same result, that if I have 34
posts, /page/4
does not work.
Just a few things to add in case they are somehow linked.
In my permalinks settings, I have a custom structure of
/%category%/%postname%/
and my default category base is .
In my WP Download Manager Settings, my WPDM Category URL Base
is .
I also have these 2 filter functions, that were copied from answers on here, and I am quite new to Wordpress so I am not sure of the potential repercussions of using these are?
add_filter('category_rewrite_rules', 'vipx_filter_category_rewrite_rules');
add_filter('user_trailingslashit', 'remove_category', 100, 2);
function vipx_filter_category_rewrite_rules($rules) {
$categories = get_categories(array('hide_empty' => false));
if (is_array($categories) && !empty($categories)) {
$slugs = array();
foreach($categories as $category) {
if (is_object($category) && !is_wp_error($category)) {
if (0 == $category - > category_parent) {
$slugs[] = $category - > slug;
} else {
$slugs[] = trim(get_category_parents($category - > term_id, false, '/', true), '/');
}
}
}
if (!empty($slugs)) {
$rules = array();
foreach($slugs as $slug) {
$rules['('.$slug.
')/feed/(feed|rdf|rss|rss2|atom)?/?$'] = 'index.php?category_name=$matches[1]&feed=$matches[2]';
$rules['('.$slug.
')/(feed|rdf|rss|rss2|atom)/?$'] = 'index.php?category_name=$matches[1]&feed=$matches[2]';
$rules['('.$slug.
')(/page/(\d+)/?)?$'] = 'index.php?category_name=$matches[1]&paged=$matches[3]';
}
}
}
return $rules;
}
function remove_category($string, $type) {
if ($type != 'single' && $type == 'category' && (strpos($string, 'category') !== false)) {
$url_without_category = str_replace("/wpdmcategory/", "/", $string);
return trailingslashit($url_without_category);
}
return $string;
}
echo $wp_query->max_num_pages;
Returns 3
when I have a total of 34
normal posts, how do I set this to use my custom post type to get the correct number of pages?