wordpress pagination category 404 on page 2












1















When I click on the next page of my pagination, transfer me to page 404. I tried everything, but there was no success. I'm not sure if I need to insert something into functions.php or in a URL. Here's my code:
Here's my code:



<ul>
<?php
$paged = (get_query_var('paged')) ? absint(get_query_var('paged')) : 1;
$monthnum = (get_query_var('monthnum')) ? absint(get_query_var('monthnum')) : -1;
$year = (get_query_var('year')) ? absint(get_query_var('year')) : -1;

$args = array(
'post_type' => 'post',
'posts_per_page' => 5,
'taxonomy' => 'category',
'field' => 'slug',
'paged' => $paged,
);
if($monthnum != -1 && $year != -1){
$args["monthnum"] = $monthnum;
$args["year"] = $year;
}
$posts = new WP_Query($args);
if ($posts->have_posts()) {
while ($posts->have_posts()) {
$posts->the_post();
?>
<li>
<span class="date"><?php echo get_the_time('d.m.y') ?></span>
<a href="<?php echo get_the_permalink(); ?>"><h3><?php the_title() ?></h3></a>
<div class="postContent">
<!-- start postContent -->
<div class="postExcerpt"><?php the_excerpt(); ?></div>
<div class="permalink"><a href="<?php echo get_the_permalink(); ?>">Read More</a></div>
</div>
<!-- end postContent -->
</li>
<?php } ?>
<div class="pagination">
<!-- start pagination-->
<?php $big = 999999999; // need an unlikely integer
echo paginate_links(array(
'base' => str_replace($big, '%#%',esc_url(get_pagenum_link($big))),
'format' => '/paged/%#%',
'current' => max(1, $paged),
'total' => $posts->max_num_pages,
'mid_size' => 1,
'prev_text' => "<",
'next_text' => ">"
));
?>
</div>
<?php
} else {
echo 'No matching results found. Please modify your
search criteria and try searching again.!';
}
?>

<!-- end pagination-->
</ul>









share|improve this question

























  • What do you mean by "other side of pagination" and "throw out the page 404"?

    – zipkundan
    Nov 14 '18 at 16:21











  • Sorry, now i edit my question.

    – Stefan Loncaric
    Nov 14 '18 at 16:44











  • Are you using child theme?

    – Gufran Hasan
    Nov 14 '18 at 17:08
















1















When I click on the next page of my pagination, transfer me to page 404. I tried everything, but there was no success. I'm not sure if I need to insert something into functions.php or in a URL. Here's my code:
Here's my code:



<ul>
<?php
$paged = (get_query_var('paged')) ? absint(get_query_var('paged')) : 1;
$monthnum = (get_query_var('monthnum')) ? absint(get_query_var('monthnum')) : -1;
$year = (get_query_var('year')) ? absint(get_query_var('year')) : -1;

$args = array(
'post_type' => 'post',
'posts_per_page' => 5,
'taxonomy' => 'category',
'field' => 'slug',
'paged' => $paged,
);
if($monthnum != -1 && $year != -1){
$args["monthnum"] = $monthnum;
$args["year"] = $year;
}
$posts = new WP_Query($args);
if ($posts->have_posts()) {
while ($posts->have_posts()) {
$posts->the_post();
?>
<li>
<span class="date"><?php echo get_the_time('d.m.y') ?></span>
<a href="<?php echo get_the_permalink(); ?>"><h3><?php the_title() ?></h3></a>
<div class="postContent">
<!-- start postContent -->
<div class="postExcerpt"><?php the_excerpt(); ?></div>
<div class="permalink"><a href="<?php echo get_the_permalink(); ?>">Read More</a></div>
</div>
<!-- end postContent -->
</li>
<?php } ?>
<div class="pagination">
<!-- start pagination-->
<?php $big = 999999999; // need an unlikely integer
echo paginate_links(array(
'base' => str_replace($big, '%#%',esc_url(get_pagenum_link($big))),
'format' => '/paged/%#%',
'current' => max(1, $paged),
'total' => $posts->max_num_pages,
'mid_size' => 1,
'prev_text' => "<",
'next_text' => ">"
));
?>
</div>
<?php
} else {
echo 'No matching results found. Please modify your
search criteria and try searching again.!';
}
?>

<!-- end pagination-->
</ul>









share|improve this question

























  • What do you mean by "other side of pagination" and "throw out the page 404"?

    – zipkundan
    Nov 14 '18 at 16:21











  • Sorry, now i edit my question.

    – Stefan Loncaric
    Nov 14 '18 at 16:44











  • Are you using child theme?

    – Gufran Hasan
    Nov 14 '18 at 17:08














1












1








1








When I click on the next page of my pagination, transfer me to page 404. I tried everything, but there was no success. I'm not sure if I need to insert something into functions.php or in a URL. Here's my code:
Here's my code:



<ul>
<?php
$paged = (get_query_var('paged')) ? absint(get_query_var('paged')) : 1;
$monthnum = (get_query_var('monthnum')) ? absint(get_query_var('monthnum')) : -1;
$year = (get_query_var('year')) ? absint(get_query_var('year')) : -1;

$args = array(
'post_type' => 'post',
'posts_per_page' => 5,
'taxonomy' => 'category',
'field' => 'slug',
'paged' => $paged,
);
if($monthnum != -1 && $year != -1){
$args["monthnum"] = $monthnum;
$args["year"] = $year;
}
$posts = new WP_Query($args);
if ($posts->have_posts()) {
while ($posts->have_posts()) {
$posts->the_post();
?>
<li>
<span class="date"><?php echo get_the_time('d.m.y') ?></span>
<a href="<?php echo get_the_permalink(); ?>"><h3><?php the_title() ?></h3></a>
<div class="postContent">
<!-- start postContent -->
<div class="postExcerpt"><?php the_excerpt(); ?></div>
<div class="permalink"><a href="<?php echo get_the_permalink(); ?>">Read More</a></div>
</div>
<!-- end postContent -->
</li>
<?php } ?>
<div class="pagination">
<!-- start pagination-->
<?php $big = 999999999; // need an unlikely integer
echo paginate_links(array(
'base' => str_replace($big, '%#%',esc_url(get_pagenum_link($big))),
'format' => '/paged/%#%',
'current' => max(1, $paged),
'total' => $posts->max_num_pages,
'mid_size' => 1,
'prev_text' => "<",
'next_text' => ">"
));
?>
</div>
<?php
} else {
echo 'No matching results found. Please modify your
search criteria and try searching again.!';
}
?>

<!-- end pagination-->
</ul>









share|improve this question
















When I click on the next page of my pagination, transfer me to page 404. I tried everything, but there was no success. I'm not sure if I need to insert something into functions.php or in a URL. Here's my code:
Here's my code:



<ul>
<?php
$paged = (get_query_var('paged')) ? absint(get_query_var('paged')) : 1;
$monthnum = (get_query_var('monthnum')) ? absint(get_query_var('monthnum')) : -1;
$year = (get_query_var('year')) ? absint(get_query_var('year')) : -1;

$args = array(
'post_type' => 'post',
'posts_per_page' => 5,
'taxonomy' => 'category',
'field' => 'slug',
'paged' => $paged,
);
if($monthnum != -1 && $year != -1){
$args["monthnum"] = $monthnum;
$args["year"] = $year;
}
$posts = new WP_Query($args);
if ($posts->have_posts()) {
while ($posts->have_posts()) {
$posts->the_post();
?>
<li>
<span class="date"><?php echo get_the_time('d.m.y') ?></span>
<a href="<?php echo get_the_permalink(); ?>"><h3><?php the_title() ?></h3></a>
<div class="postContent">
<!-- start postContent -->
<div class="postExcerpt"><?php the_excerpt(); ?></div>
<div class="permalink"><a href="<?php echo get_the_permalink(); ?>">Read More</a></div>
</div>
<!-- end postContent -->
</li>
<?php } ?>
<div class="pagination">
<!-- start pagination-->
<?php $big = 999999999; // need an unlikely integer
echo paginate_links(array(
'base' => str_replace($big, '%#%',esc_url(get_pagenum_link($big))),
'format' => '/paged/%#%',
'current' => max(1, $paged),
'total' => $posts->max_num_pages,
'mid_size' => 1,
'prev_text' => "<",
'next_text' => ">"
));
?>
</div>
<?php
} else {
echo 'No matching results found. Please modify your
search criteria and try searching again.!';
}
?>

<!-- end pagination-->
</ul>






php html wordpress






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 14 '18 at 18:32









Gufran Hasan

3,57241426




3,57241426










asked Nov 14 '18 at 15:29









Stefan LoncaricStefan Loncaric

125




125













  • What do you mean by "other side of pagination" and "throw out the page 404"?

    – zipkundan
    Nov 14 '18 at 16:21











  • Sorry, now i edit my question.

    – Stefan Loncaric
    Nov 14 '18 at 16:44











  • Are you using child theme?

    – Gufran Hasan
    Nov 14 '18 at 17:08



















  • What do you mean by "other side of pagination" and "throw out the page 404"?

    – zipkundan
    Nov 14 '18 at 16:21











  • Sorry, now i edit my question.

    – Stefan Loncaric
    Nov 14 '18 at 16:44











  • Are you using child theme?

    – Gufran Hasan
    Nov 14 '18 at 17:08

















What do you mean by "other side of pagination" and "throw out the page 404"?

– zipkundan
Nov 14 '18 at 16:21





What do you mean by "other side of pagination" and "throw out the page 404"?

– zipkundan
Nov 14 '18 at 16:21













Sorry, now i edit my question.

– Stefan Loncaric
Nov 14 '18 at 16:44





Sorry, now i edit my question.

– Stefan Loncaric
Nov 14 '18 at 16:44













Are you using child theme?

– Gufran Hasan
Nov 14 '18 at 17:08





Are you using child theme?

– Gufran Hasan
Nov 14 '18 at 17:08












2 Answers
2






active

oldest

votes


















1














You need to modify query as:



$paged = (get_query_var('page_val') ? get_query_var('page_val') : 1);
$query = new WP_Query(array(
'post_type' => 'post',
'posts_per_page' => 3,
'cat' => $cat,
'orderby' => 'date',
'paged' => $paged,
'order' => 'DESC'
)
);


For pagination, I changed this code like this. Hope this will help you:



$big = 999999999;  
echo paginate_links(array(
'base' => str_replace($big, '%#%', esc_url(get_pagenum_link($big))),
'format' => '/page/%#%',
'current' => max(1, $paged),
'prev_text' => __('Previous Page'),
'next_text' => __('Next Page'),
'show_all' => true,
'total' => $query->max_num_pages
));





share|improve this answer
























  • Again same, page 404 :/

    – Stefan Loncaric
    Nov 14 '18 at 17:22



















0














I combined the code from the answer Gufran Hasan, and add this code on my function.php. Problem solved!



Thanks man! Gufran Hasan



Code:



function custom_pre_get_posts($query)
{
if ($query->is_main_query() && !$query->is_feed() && !is_admin() && is_category()) {
$query->set('page_val', get_query_var('paged'));
$query->set('paged', 0);
}
}

add_action('pre_get_posts', 'custom_pre_get_posts');





share|improve this answer
























  • Now it's working?

    – Gufran Hasan
    Nov 14 '18 at 17:54











  • Yea, thank you man :)

    – Stefan Loncaric
    Nov 14 '18 at 18:25











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53303608%2fwordpress-pagination-category-404-on-page-2%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














You need to modify query as:



$paged = (get_query_var('page_val') ? get_query_var('page_val') : 1);
$query = new WP_Query(array(
'post_type' => 'post',
'posts_per_page' => 3,
'cat' => $cat,
'orderby' => 'date',
'paged' => $paged,
'order' => 'DESC'
)
);


For pagination, I changed this code like this. Hope this will help you:



$big = 999999999;  
echo paginate_links(array(
'base' => str_replace($big, '%#%', esc_url(get_pagenum_link($big))),
'format' => '/page/%#%',
'current' => max(1, $paged),
'prev_text' => __('Previous Page'),
'next_text' => __('Next Page'),
'show_all' => true,
'total' => $query->max_num_pages
));





share|improve this answer
























  • Again same, page 404 :/

    – Stefan Loncaric
    Nov 14 '18 at 17:22
















1














You need to modify query as:



$paged = (get_query_var('page_val') ? get_query_var('page_val') : 1);
$query = new WP_Query(array(
'post_type' => 'post',
'posts_per_page' => 3,
'cat' => $cat,
'orderby' => 'date',
'paged' => $paged,
'order' => 'DESC'
)
);


For pagination, I changed this code like this. Hope this will help you:



$big = 999999999;  
echo paginate_links(array(
'base' => str_replace($big, '%#%', esc_url(get_pagenum_link($big))),
'format' => '/page/%#%',
'current' => max(1, $paged),
'prev_text' => __('Previous Page'),
'next_text' => __('Next Page'),
'show_all' => true,
'total' => $query->max_num_pages
));





share|improve this answer
























  • Again same, page 404 :/

    – Stefan Loncaric
    Nov 14 '18 at 17:22














1












1








1







You need to modify query as:



$paged = (get_query_var('page_val') ? get_query_var('page_val') : 1);
$query = new WP_Query(array(
'post_type' => 'post',
'posts_per_page' => 3,
'cat' => $cat,
'orderby' => 'date',
'paged' => $paged,
'order' => 'DESC'
)
);


For pagination, I changed this code like this. Hope this will help you:



$big = 999999999;  
echo paginate_links(array(
'base' => str_replace($big, '%#%', esc_url(get_pagenum_link($big))),
'format' => '/page/%#%',
'current' => max(1, $paged),
'prev_text' => __('Previous Page'),
'next_text' => __('Next Page'),
'show_all' => true,
'total' => $query->max_num_pages
));





share|improve this answer













You need to modify query as:



$paged = (get_query_var('page_val') ? get_query_var('page_val') : 1);
$query = new WP_Query(array(
'post_type' => 'post',
'posts_per_page' => 3,
'cat' => $cat,
'orderby' => 'date',
'paged' => $paged,
'order' => 'DESC'
)
);


For pagination, I changed this code like this. Hope this will help you:



$big = 999999999;  
echo paginate_links(array(
'base' => str_replace($big, '%#%', esc_url(get_pagenum_link($big))),
'format' => '/page/%#%',
'current' => max(1, $paged),
'prev_text' => __('Previous Page'),
'next_text' => __('Next Page'),
'show_all' => true,
'total' => $query->max_num_pages
));






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 14 '18 at 17:11









Gufran HasanGufran Hasan

3,57241426




3,57241426













  • Again same, page 404 :/

    – Stefan Loncaric
    Nov 14 '18 at 17:22



















  • Again same, page 404 :/

    – Stefan Loncaric
    Nov 14 '18 at 17:22

















Again same, page 404 :/

– Stefan Loncaric
Nov 14 '18 at 17:22





Again same, page 404 :/

– Stefan Loncaric
Nov 14 '18 at 17:22













0














I combined the code from the answer Gufran Hasan, and add this code on my function.php. Problem solved!



Thanks man! Gufran Hasan



Code:



function custom_pre_get_posts($query)
{
if ($query->is_main_query() && !$query->is_feed() && !is_admin() && is_category()) {
$query->set('page_val', get_query_var('paged'));
$query->set('paged', 0);
}
}

add_action('pre_get_posts', 'custom_pre_get_posts');





share|improve this answer
























  • Now it's working?

    – Gufran Hasan
    Nov 14 '18 at 17:54











  • Yea, thank you man :)

    – Stefan Loncaric
    Nov 14 '18 at 18:25
















0














I combined the code from the answer Gufran Hasan, and add this code on my function.php. Problem solved!



Thanks man! Gufran Hasan



Code:



function custom_pre_get_posts($query)
{
if ($query->is_main_query() && !$query->is_feed() && !is_admin() && is_category()) {
$query->set('page_val', get_query_var('paged'));
$query->set('paged', 0);
}
}

add_action('pre_get_posts', 'custom_pre_get_posts');





share|improve this answer
























  • Now it's working?

    – Gufran Hasan
    Nov 14 '18 at 17:54











  • Yea, thank you man :)

    – Stefan Loncaric
    Nov 14 '18 at 18:25














0












0








0







I combined the code from the answer Gufran Hasan, and add this code on my function.php. Problem solved!



Thanks man! Gufran Hasan



Code:



function custom_pre_get_posts($query)
{
if ($query->is_main_query() && !$query->is_feed() && !is_admin() && is_category()) {
$query->set('page_val', get_query_var('paged'));
$query->set('paged', 0);
}
}

add_action('pre_get_posts', 'custom_pre_get_posts');





share|improve this answer













I combined the code from the answer Gufran Hasan, and add this code on my function.php. Problem solved!



Thanks man! Gufran Hasan



Code:



function custom_pre_get_posts($query)
{
if ($query->is_main_query() && !$query->is_feed() && !is_admin() && is_category()) {
$query->set('page_val', get_query_var('paged'));
$query->set('paged', 0);
}
}

add_action('pre_get_posts', 'custom_pre_get_posts');






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 14 '18 at 17:40









Stefan LoncaricStefan Loncaric

125




125













  • Now it's working?

    – Gufran Hasan
    Nov 14 '18 at 17:54











  • Yea, thank you man :)

    – Stefan Loncaric
    Nov 14 '18 at 18:25



















  • Now it's working?

    – Gufran Hasan
    Nov 14 '18 at 17:54











  • Yea, thank you man :)

    – Stefan Loncaric
    Nov 14 '18 at 18:25

















Now it's working?

– Gufran Hasan
Nov 14 '18 at 17:54





Now it's working?

– Gufran Hasan
Nov 14 '18 at 17:54













Yea, thank you man :)

– Stefan Loncaric
Nov 14 '18 at 18:25





Yea, thank you man :)

– Stefan Loncaric
Nov 14 '18 at 18:25


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53303608%2fwordpress-pagination-category-404-on-page-2%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

The Sandy Post

Danny Elfman

Pages that link to "Head v. Amoskeag Manufacturing Co."