最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

custom post types - How can I trace inconsistency in loading a template?

programmeradmin4浏览0评论

I have two (almost) identical wordpress websites. A devel/local and a production/remote. I have a custom post type "event" created through Meta Mask on both instances. I want to render a template "archive-event.php" by adding a "/event" request in the browser. The devel instance renders the archive-event.php well. The production instance renders a 404.php template, although the archive-event.php template is in the right place.

Query Monitor shows this:

Devel

Overview

GET http://[local site]/event/ → 200

Request

event
Matched Rule

event/?$
Matched Query

post_type=event
Query String

post_type=event

All Matching Rewrite Rules
event/?$    post_type=event
(.?.+?)(?:/([0-9]+))?/?$    pagename=$matches[1]
&page=$matches[2]
(.+?)/?$    category_name=$matches[1]

Prod

Overview

GET https://[remote site]/event/ → 404

Request

event
Matched Rule

(.+?)/?$
Matched Query

category_name=event
Query String

category_name=event

All Matching Rewrite Rules
(.?.+?)(?:/([0-9]+))?/?$    pagename=$matches[1]
&page=$matches[2]
(.+?)/?$    category_name=$matches[1]

How can I trace where is the conflict or another difference?

I have two (almost) identical wordpress websites. A devel/local and a production/remote. I have a custom post type "event" created through Meta Mask on both instances. I want to render a template "archive-event.php" by adding a "/event" request in the browser. The devel instance renders the archive-event.php well. The production instance renders a 404.php template, although the archive-event.php template is in the right place.

Query Monitor shows this:

Devel

Overview

GET http://[local site]/event/ → 200

Request

event
Matched Rule

event/?$
Matched Query

post_type=event
Query String

post_type=event

All Matching Rewrite Rules
event/?$    post_type=event
(.?.+?)(?:/([0-9]+))?/?$    pagename=$matches[1]
&page=$matches[2]
(.+?)/?$    category_name=$matches[1]

Prod

Overview

GET https://[remote site]/event/ → 404

Request

event
Matched Rule

(.+?)/?$
Matched Query

category_name=event
Query String

category_name=event

All Matching Rewrite Rules
(.?.+?)(?:/([0-9]+))?/?$    pagename=$matches[1]
&page=$matches[2]
(.+?)/?$    category_name=$matches[1]

How can I trace where is the conflict or another difference?

Share Improve this question asked Feb 1, 2022 at 9:28 Robert ZelníkRobert Zelník 1911 gold badge1 silver badge5 bronze badges 5
  • 2 If you registered the post type with a plugin then it's probably configured differently on each. Archives need to be enabled for the post type. In code that's making sure that has_archive is true, but if you used a plugin you'd need to ask its author how to do this. Third party plugins are off topic here. – Jacob Peattie Commented Feb 1, 2022 at 9:33
  • Actually there's no difference between creating a custom post type through Meta Box and through plain WordPress. It's just a code generator, so we can consider it a pluginless way. I will check the has_archive, thanks for your tip. – Robert Zelník Commented Feb 1, 2022 at 9:49
  • No, it isn't a has_archive issue. It seems to be a slug conflict. ?post_type=event works well. – Robert Zelník Commented Feb 1, 2022 at 10:01
  • Did you re-save permalink settings on the prod site? – kero Commented Feb 1, 2022 at 10:17
  • Bingo! I re-saved the permalink settings and it is working well now. Thanks for your help. – Robert Zelník Commented Feb 1, 2022 at 10:23
Add a comment  | 

1 Answer 1

Reset to default 1

The issue was caused by missing permalinks for the new content types. Re-saving the permalink settings helped.

发布评论

评论列表(0)

  1. 暂无评论