post_type_link filter causes 404 on the CPT page it's used on
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}
When i change the permalink of my CPT using filters it gives a 404. I clicked save in the permalinks settings and switched and saved, but there's still a 404. Is there some kind of hooking up i need to do with a rewrite to make this work?
function my_permalinks($permalink, $post, $leavename) {
$post_id = $post->ID;
if($post->post_type != 'model-list' || empty($permalink) || in_array($post->post_status, array('draft', 'pending', 'auto-draft')))
return $permalink;
$parent = $post->post_parent;
$parent_post = get_post( $parent );
$permalink = str_replace('model-list/', '', $permalink);
return $permalink;
}
add_filter('post_type_link', 'my_permalinks', 10, 3);
the url is looking correct, but it gives a 404
custom-post-types plugins permalinks filters
add a comment |
When i change the permalink of my CPT using filters it gives a 404. I clicked save in the permalinks settings and switched and saved, but there's still a 404. Is there some kind of hooking up i need to do with a rewrite to make this work?
function my_permalinks($permalink, $post, $leavename) {
$post_id = $post->ID;
if($post->post_type != 'model-list' || empty($permalink) || in_array($post->post_status, array('draft', 'pending', 'auto-draft')))
return $permalink;
$parent = $post->post_parent;
$parent_post = get_post( $parent );
$permalink = str_replace('model-list/', '', $permalink);
return $permalink;
}
add_filter('post_type_link', 'my_permalinks', 10, 3);
the url is looking correct, but it gives a 404
custom-post-types plugins permalinks filters
add a comment |
When i change the permalink of my CPT using filters it gives a 404. I clicked save in the permalinks settings and switched and saved, but there's still a 404. Is there some kind of hooking up i need to do with a rewrite to make this work?
function my_permalinks($permalink, $post, $leavename) {
$post_id = $post->ID;
if($post->post_type != 'model-list' || empty($permalink) || in_array($post->post_status, array('draft', 'pending', 'auto-draft')))
return $permalink;
$parent = $post->post_parent;
$parent_post = get_post( $parent );
$permalink = str_replace('model-list/', '', $permalink);
return $permalink;
}
add_filter('post_type_link', 'my_permalinks', 10, 3);
the url is looking correct, but it gives a 404
custom-post-types plugins permalinks filters
When i change the permalink of my CPT using filters it gives a 404. I clicked save in the permalinks settings and switched and saved, but there's still a 404. Is there some kind of hooking up i need to do with a rewrite to make this work?
function my_permalinks($permalink, $post, $leavename) {
$post_id = $post->ID;
if($post->post_type != 'model-list' || empty($permalink) || in_array($post->post_status, array('draft', 'pending', 'auto-draft')))
return $permalink;
$parent = $post->post_parent;
$parent_post = get_post( $parent );
$permalink = str_replace('model-list/', '', $permalink);
return $permalink;
}
add_filter('post_type_link', 'my_permalinks', 10, 3);
the url is looking correct, but it gives a 404
custom-post-types plugins permalinks filters
custom-post-types plugins permalinks filters
asked Apr 21 at 8:09
Tintinabulator ZeaTintinabulator Zea
796
796
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
post_type_link
is a filter that is applied to the URL for a post before it’s returned by get_post_permalink
.
So it doesn’t change any rewrite rules and the structure of permalinks is still the same.
So yeah - if you use it to change the structure of links, you have also to change the rewrite rules in such way, that the new link is matched and processed correctly.
ok thank you, but what should i put in add_rewrite_rule ?
– Tintinabulator Zea
Apr 21 at 8:25
i am removing the CPT name from the url, so i don't think I can find it on index.php because the permalink doesn't contain post_type info
– Tintinabulator Zea
Apr 21 at 8:32
i used this guide to try and do it 1fix.io/blog/2016/02/05/parent-from-another-cpt i set the CPT to have a page that's a parent, it actually works if i don't set the parent
– Tintinabulator Zea
Apr 21 at 8:35
@TintinabulatorZea if you’re removing CPT name, then it won’t be so easy to match these posts using only rewrite rules - these patterns will cause conflicts (there is no way to tell if WP should look for your CPT or a normal page). In such case you have to write some custom code that will check what type of post to search for and get that post. There’s a good answer on how to remove CPT slug from URL somewhere in here (I’m on mobile currently, so it’s not so easy for me to find it, sorry)
– Krzysiek Dróżdż♦
Apr 21 at 8:54
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "110"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fwordpress.stackexchange.com%2fquestions%2f334898%2fpost-type-link-filter-causes-404-on-the-cpt-page-its-used-on%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
post_type_link
is a filter that is applied to the URL for a post before it’s returned by get_post_permalink
.
So it doesn’t change any rewrite rules and the structure of permalinks is still the same.
So yeah - if you use it to change the structure of links, you have also to change the rewrite rules in such way, that the new link is matched and processed correctly.
ok thank you, but what should i put in add_rewrite_rule ?
– Tintinabulator Zea
Apr 21 at 8:25
i am removing the CPT name from the url, so i don't think I can find it on index.php because the permalink doesn't contain post_type info
– Tintinabulator Zea
Apr 21 at 8:32
i used this guide to try and do it 1fix.io/blog/2016/02/05/parent-from-another-cpt i set the CPT to have a page that's a parent, it actually works if i don't set the parent
– Tintinabulator Zea
Apr 21 at 8:35
@TintinabulatorZea if you’re removing CPT name, then it won’t be so easy to match these posts using only rewrite rules - these patterns will cause conflicts (there is no way to tell if WP should look for your CPT or a normal page). In such case you have to write some custom code that will check what type of post to search for and get that post. There’s a good answer on how to remove CPT slug from URL somewhere in here (I’m on mobile currently, so it’s not so easy for me to find it, sorry)
– Krzysiek Dróżdż♦
Apr 21 at 8:54
add a comment |
post_type_link
is a filter that is applied to the URL for a post before it’s returned by get_post_permalink
.
So it doesn’t change any rewrite rules and the structure of permalinks is still the same.
So yeah - if you use it to change the structure of links, you have also to change the rewrite rules in such way, that the new link is matched and processed correctly.
ok thank you, but what should i put in add_rewrite_rule ?
– Tintinabulator Zea
Apr 21 at 8:25
i am removing the CPT name from the url, so i don't think I can find it on index.php because the permalink doesn't contain post_type info
– Tintinabulator Zea
Apr 21 at 8:32
i used this guide to try and do it 1fix.io/blog/2016/02/05/parent-from-another-cpt i set the CPT to have a page that's a parent, it actually works if i don't set the parent
– Tintinabulator Zea
Apr 21 at 8:35
@TintinabulatorZea if you’re removing CPT name, then it won’t be so easy to match these posts using only rewrite rules - these patterns will cause conflicts (there is no way to tell if WP should look for your CPT or a normal page). In such case you have to write some custom code that will check what type of post to search for and get that post. There’s a good answer on how to remove CPT slug from URL somewhere in here (I’m on mobile currently, so it’s not so easy for me to find it, sorry)
– Krzysiek Dróżdż♦
Apr 21 at 8:54
add a comment |
post_type_link
is a filter that is applied to the URL for a post before it’s returned by get_post_permalink
.
So it doesn’t change any rewrite rules and the structure of permalinks is still the same.
So yeah - if you use it to change the structure of links, you have also to change the rewrite rules in such way, that the new link is matched and processed correctly.
post_type_link
is a filter that is applied to the URL for a post before it’s returned by get_post_permalink
.
So it doesn’t change any rewrite rules and the structure of permalinks is still the same.
So yeah - if you use it to change the structure of links, you have also to change the rewrite rules in such way, that the new link is matched and processed correctly.
answered Apr 21 at 8:23
Krzysiek Dróżdż♦Krzysiek Dróżdż
18.9k73350
18.9k73350
ok thank you, but what should i put in add_rewrite_rule ?
– Tintinabulator Zea
Apr 21 at 8:25
i am removing the CPT name from the url, so i don't think I can find it on index.php because the permalink doesn't contain post_type info
– Tintinabulator Zea
Apr 21 at 8:32
i used this guide to try and do it 1fix.io/blog/2016/02/05/parent-from-another-cpt i set the CPT to have a page that's a parent, it actually works if i don't set the parent
– Tintinabulator Zea
Apr 21 at 8:35
@TintinabulatorZea if you’re removing CPT name, then it won’t be so easy to match these posts using only rewrite rules - these patterns will cause conflicts (there is no way to tell if WP should look for your CPT or a normal page). In such case you have to write some custom code that will check what type of post to search for and get that post. There’s a good answer on how to remove CPT slug from URL somewhere in here (I’m on mobile currently, so it’s not so easy for me to find it, sorry)
– Krzysiek Dróżdż♦
Apr 21 at 8:54
add a comment |
ok thank you, but what should i put in add_rewrite_rule ?
– Tintinabulator Zea
Apr 21 at 8:25
i am removing the CPT name from the url, so i don't think I can find it on index.php because the permalink doesn't contain post_type info
– Tintinabulator Zea
Apr 21 at 8:32
i used this guide to try and do it 1fix.io/blog/2016/02/05/parent-from-another-cpt i set the CPT to have a page that's a parent, it actually works if i don't set the parent
– Tintinabulator Zea
Apr 21 at 8:35
@TintinabulatorZea if you’re removing CPT name, then it won’t be so easy to match these posts using only rewrite rules - these patterns will cause conflicts (there is no way to tell if WP should look for your CPT or a normal page). In such case you have to write some custom code that will check what type of post to search for and get that post. There’s a good answer on how to remove CPT slug from URL somewhere in here (I’m on mobile currently, so it’s not so easy for me to find it, sorry)
– Krzysiek Dróżdż♦
Apr 21 at 8:54
ok thank you, but what should i put in add_rewrite_rule ?
– Tintinabulator Zea
Apr 21 at 8:25
ok thank you, but what should i put in add_rewrite_rule ?
– Tintinabulator Zea
Apr 21 at 8:25
i am removing the CPT name from the url, so i don't think I can find it on index.php because the permalink doesn't contain post_type info
– Tintinabulator Zea
Apr 21 at 8:32
i am removing the CPT name from the url, so i don't think I can find it on index.php because the permalink doesn't contain post_type info
– Tintinabulator Zea
Apr 21 at 8:32
i used this guide to try and do it 1fix.io/blog/2016/02/05/parent-from-another-cpt i set the CPT to have a page that's a parent, it actually works if i don't set the parent
– Tintinabulator Zea
Apr 21 at 8:35
i used this guide to try and do it 1fix.io/blog/2016/02/05/parent-from-another-cpt i set the CPT to have a page that's a parent, it actually works if i don't set the parent
– Tintinabulator Zea
Apr 21 at 8:35
@TintinabulatorZea if you’re removing CPT name, then it won’t be so easy to match these posts using only rewrite rules - these patterns will cause conflicts (there is no way to tell if WP should look for your CPT or a normal page). In such case you have to write some custom code that will check what type of post to search for and get that post. There’s a good answer on how to remove CPT slug from URL somewhere in here (I’m on mobile currently, so it’s not so easy for me to find it, sorry)
– Krzysiek Dróżdż♦
Apr 21 at 8:54
@TintinabulatorZea if you’re removing CPT name, then it won’t be so easy to match these posts using only rewrite rules - these patterns will cause conflicts (there is no way to tell if WP should look for your CPT or a normal page). In such case you have to write some custom code that will check what type of post to search for and get that post. There’s a good answer on how to remove CPT slug from URL somewhere in here (I’m on mobile currently, so it’s not so easy for me to find it, sorry)
– Krzysiek Dróżdż♦
Apr 21 at 8:54
add a comment |
Thanks for contributing an answer to WordPress Development Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fwordpress.stackexchange.com%2fquestions%2f334898%2fpost-type-link-filter-causes-404-on-the-cpt-page-its-used-on%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown