Menu

A Page of Custom Posts with Paginated Navigation

When I redesigned my website, I thought it would be fun to add a section where I could write about things that interest me, share helpful resources, and post inspiration. I wanted a place to muse.

I use custom post types for my portfolio work and decided to do the same thing for the “Musings” section. Essentially, I needed to create a page of custom posts that has paginated navigation on the bottom so visitors can easily view older posts. It seemed simple enough, but it turned out to be a little bit tricksy as Gollum would say…

First I made a page called Musings. Then I created a custom post type (via the Custom Post Type UI plugin) that was also called Musings. I made a template called content-musings.php and added some code to allow for pagination.

The main page for Musings would be located at nicolekikijaffe.com/musings/. I was hoping that clicking on the link to page 2 would take visitors to nicolekikijaffe.com/musings/page/2/. Instead I was greeted by a lovely 404 error page, and I was not amused.

Toto, I don’t wanna be in 404-Land anymore…

I did a bunch of different tests changing the name of the page, the custom post type, and the custom post type slug. I also kept methodically resaving the permalinks in case that was the issue. In the end, I learned a valuable lesson (later confirmed by a post on the wordpress forums).

It turns out that WordPress Pages and Custom Post Types cannot have the same name if you want to use pagination. Don’t try it. Bad stuff happens…

In light of this newfound information, here’s what I did instead:

I created a Page called Musings to hold all the custom posts.

Instead of reusing Musings for the custom post type, I called it Musing (singular).

I did not reset the custom post type rewrite slug, so each musing post is located at nicolekikijaffe.com/musing/postname

Finally, I resaved the permalinks using the postname and…

IT WORKED! Hooray!

Though this solution bothers me a little bit, I think it makes sense because the Musings page contains many different Musings, while a Musing post is just one Musing.