0

Here's a mystery for you. I created a Custom Post Type called "portfolio". Then I wanted a page template to show just those CPT's. It's a custom loop with paging, and it works perfectly if I don't call the page "portfolio" (that is, the permalink) - if I use that, it shows my static home page instead, no loop output. Very odd, since the page I'm using is not the front page.

My first thought is that maybe by using a permalink that matches the CPT name, I'm running into some standard core loop or something.

Or maybe I should just use an archive template instead of using a page template? I was considering the page template so I could have some custom output on the first page, maybe via a custom field.

I am using a cache, but I tried clearing the cache and even disabling it. Same thing.

Any thoughts?

My permalink structure is /%post-name%/

Thanks!

0

I have had similar mysterious behaviour with CPTs and pretty permalinks. Try to regenerate your permalinks by switching to another structure and back again.

Or check out flush_rewrite_rules() in the codex.

https://codex.wordpress.org/Function_Reference/flush_rewrite_rules

  • Or add the flush_rewrite_rules() somewhere in your functions.php. No, you cannot add it anywhere. Have you actually read the page you are linking to – Pieter Goosen May 11 '15 at 10:31
  • I didn't say "anywhere" but I have edited the answer to avoid misunderstandings. – JimboSlice May 11 '15 at 10:59
  • Jimbo, (btw, great moniker!) I had actually tried that before with no result, but crazily, when I re-created the page, saved, & right then did the permalinks save, bang, that was it! The timing. I remember a plugin once that would create pages (boo!), and after uninstalling it, a $%$% transient in the permalink settings screwed up a legit page. :) Thanks! – Flamenco May 11 '15 at 18:13
0

I know the feeling. I constantly have this battle between an archive slug and a static page called the same thing. i.e. Portfolio CPT archive and www.yoursite.com/portfolio page with editable content.

I have two ways to accomplish this, both fairly hacky (which I hate):

  1. Create archive-{portfolio_cpt}.php archive template and include a static page template location as the entire contents of that .php file:

    include (TEMPLATEPATH . '/your-portfolio-page-template.php');

Then apply that page template to your portfolio page - then it will work like a normal page template.

Or,

  1. You can use the standard archive-{portfolio_cpt}.php but instead of using normal template functions such as the_content(), etc, you can use custom queries to get the fields and data from the post id of the portfolio static page. i.e.

Hope that is some help.

  • John, Thanks for those clever ideas. I use workarounds for many things, but I'm with you... anything too hacky feels unsavory. In fact, I ended up using an archive template (instead of a page one) exactly as you suggested. It's been a journey getting used to the names that "alert" WP to going down particular paths. Thanks! – Flamenco May 11 '15 at 18:06
  • Hey Flamenco, glad you found it helpful. Would you mind up-voting my answer? Thanks! – johncarter May 12 '15 at 9:24
  • John, Glad to... I'm a newbie, so it may be a little while! Thx, D – Flamenco May 12 '15 at 13:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.