When I use the archive widget in a sidebar, it creates the normal monthly post archive listing like the following:

  • February 2014
  • January 2014
  • October 2013

and so on. Whenever I click on these links, I get a 404 page.

The urls generated by the archive widget for monthly listings are in this format:

www.mysite.com/pedestrian/2014/02/

However, manually entering the following url style works:

www.mysite.com/pedestrian/?post_type=news&year=2014&monthnum=02

This shows exactly what I would expect to see (all the posts from February 2014).

I believe that the following code will fix my issue, but I am at a loss as to where to put it.

// Add day archive (and pagination)
add_rewrite_rule("pedestrian/([0-9]{4})/([0-9]{2})/([0-9]{2})/page/?([0-9]{1,})/?",'index.php?post_type=news&year=$matches[1]&monthnum=$matches[2]&day=$matches[3]&paged=$matches[4]','top');
add_rewrite_rule("pedestrian/([0-9]{4})/([0-9]{2})/([0-9]{2})/?",'index.php?post_type=news&year=$matches[1]&monthnum=$matches[2]&day=$matches[3]','top');
// Add month archive (and pagination)
add_rewrite_rule("pedestrian/([0-9]{4})/([0-9]{2})/page/?([0-9]{1,})/?",'index.php?post_type=news&year=$matches[1]&monthnum=$matches[2]&paged=$matches[3]','top');
add_rewrite_rule("pedestrian/([0-9]{4})/([0-9]{2})/?",'index.php?post_type=news&year=$matches[1]&monthnum=$matches[2]','top');
// Add year archive (and pagination)
add_rewrite_rule("pedestrian/([0-9]{4})/page/?([0-9]{1,})/?",'index.php?post_type=news&year=$matches[1]&paged=$matches[2]','top');
add_rewrite_rule("pedestrian/([0-9]{4})/?",'index.php?post_type=news&year=$matches[1]','top');

So, am i on the right track and if so where do i put this code? Thanks!

Read more here:: WordPress monthly archive links result in 404


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.


Wordpress related questions and answers: