Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

WordPress Build a Website with WordPress Custom Post Types and Fields in WordPress Custom Post Type Templates

Vicki Greer
Vicki Greer
5,020 Points

WordPress error creating permalinks with custom post type

Hi,

I've added a custom post type that I called "author". When I add a new author, I can see that the permalink is /localhost/wordpress/author/james-jones. I added a new page with the author page as a template, and it displays the new posts correctly. However, if I click on one of the post titles, I get a 404 error.

I discovered that if I edit the author post and change the permalink to /localhost/wordpress/author/james_jones (with an underscore between the first and last names, instead of a hyphen) that I can then link from my author page to that post correctly.

How do I tell wordpress to use an underscore for a blank space when creating the permalinks? I don't want to have to change the permalink on each post by hand before I publish it.

[edited on 3/20/17] Okay, I found a little more information about this. It's the plug-in Custom Post Types UI that is forcing the use of the underscore. For some reason, the "art" post type created in the demo works correctly -- maybe because there are no spaces in the post titles? -- but my custom post type "author" uses the hyphen in the permalink and the underscore wherever the page is created. So I end up with a permalink looking like: ..wordpress/author/john-jones and an actual page that is ...wordpress/author/john_jones. So on my All Authors page, wordpress can't link to the permalink because that page doesn't exist.

I found a tutorial on the support site for Custom Post Types UI, but it doesn't give enough information for me to know how to fix the problem. The tutorial is at (http://docs.pluginize.com/article/27-changing-post-type-or-taxonomy-slugs). It recommends changing the Custom Rewrite Slug field to fix this problem, but it doesn't tell me what to change that field to contain.

Help! Vicki