admin管理员组文章数量:1405768
I've been battling with this for a while. I have a CPT created with PostTypes (I have used this library many many times in other projects w/o problems):
$volunteer = new PostType( 'volunteer' );
$volunteer->options(
array(
'supports' => array( 'title' ),
'capability_type' => 'post',
'publicly_queryable' => true,
'show_in_rest' => false,
'has_archive' => true,
'public' => true,
'show_ui' => true,
'rewrite' => array(
'slug' => 'volunteers',
),
)
);
$volunteer->icon( 'dashicons-groups' );
$volunteer->register();
I have opened Options->Permalinks
and saved settings so that permalinks will display as Post name.
I have created a couple of volunteer posts.
In one page I am using a custom query to bring the results. I create a link to the post by using the permalink which renders this URL:
http://localhost:8888/compeer/volunteer-2/
Which is odd because (AFAIK) should be:
http://localhost:8888/compeer/volunteers/volunteer-2/
When I click the link, I get a 404. When I type in the second permalink, I immediately get sent to the home page, it does not show an error. I have tried to debug this in index.php but by the time the breakpoint hits, it's referring to info on the page.
I have added archive-volunteer.php and single-volunteer.php and they never get invoked no matter what I do.
This has really left me baffled, I don't think I'm making a careless mistake anywhere.
Has anyone experience anything like this before or can recommend any tools that might lead me in the right direction? I already have installed Show Current Template.
Thanks in advance!
I've been battling with this for a while. I have a CPT created with PostTypes (I have used this library many many times in other projects w/o problems):
$volunteer = new PostType( 'volunteer' );
$volunteer->options(
array(
'supports' => array( 'title' ),
'capability_type' => 'post',
'publicly_queryable' => true,
'show_in_rest' => false,
'has_archive' => true,
'public' => true,
'show_ui' => true,
'rewrite' => array(
'slug' => 'volunteers',
),
)
);
$volunteer->icon( 'dashicons-groups' );
$volunteer->register();
I have opened Options->Permalinks
and saved settings so that permalinks will display as Post name.
I have created a couple of volunteer posts.
In one page I am using a custom query to bring the results. I create a link to the post by using the permalink which renders this URL:
http://localhost:8888/compeer/volunteer-2/
Which is odd because (AFAIK) should be:
http://localhost:8888/compeer/volunteers/volunteer-2/
When I click the link, I get a 404. When I type in the second permalink, I immediately get sent to the home page, it does not show an error. I have tried to debug this in index.php but by the time the breakpoint hits, it's referring to info on the page.
I have added archive-volunteer.php and single-volunteer.php and they never get invoked no matter what I do.
This has really left me baffled, I don't think I'm making a careless mistake anywhere.
Has anyone experience anything like this before or can recommend any tools that might lead me in the right direction? I already have installed Show Current Template.
Thanks in advance!
Share Improve this question edited Dec 9, 2019 at 6:47 csaborio asked Dec 9, 2019 at 6:17 csaboriocsaborio 1122 silver badges13 bronze badges 4 |1 Answer
Reset to default 0After hours of debugging I noticed that the problem was only reproduced when I used the library. Even if I used register_post_type, if I used any other functionality from the library before the register_post_type function call, it would cause some erratic behaviour.
I opted on removing PostTypes from my project and simply sticking to register_post_type and everything works as expected. Third-party libraries are nice and can be a godsend, but unless you are ready to get down and dirty debugging someone else's code when things got astray, I can only recommend to steer clear of them.
Thanks to everyone who took the time to read and pitch in, much appreciated.
本文标签: permalinksCustom Post Type Single Page and Archive Page redirects to Home Page
版权声明:本文标题:permalinks - Custom Post Type Single Page and Archive Page redirects to Home Page 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744923769a2632461.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
register_post_type()
, rather than this library, does it work? – Jacob Peattie Commented Dec 9, 2019 at 6:33new PostType( 'volunteer' )
. There's noPostType
class in WordPress either. Where is this coming from? – Jacob Peattie Commented Dec 9, 2019 at 6:35