最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

permalinks - WordPress Custom Post Type is Matching on Partial Slug

matteradmin4PV0评论

I'm having a really weird issue. For example, there is a custom post 'people'. The post title is the name of the person and pretty permalinks are enabled. Say we have a person custom post with the name of 'John Smith' with a slug of 'john-smith'. If I visit the URL example/jo, it still redirects me to the URL example/john-smith.

I've never seen this behaviour in WordPress before. Does anyone know what might be causing it?

I'm having a really weird issue. For example, there is a custom post 'people'. The post title is the name of the person and pretty permalinks are enabled. Say we have a person custom post with the name of 'John Smith' with a slug of 'john-smith'. If I visit the URL example/jo, it still redirects me to the URL example/john-smith.

I've never seen this behaviour in WordPress before. Does anyone know what might be causing it?

Share Improve this question edited Oct 11, 2016 at 15:13 Max Yudin 6,3882 gold badges26 silver badges36 bronze badges asked Oct 11, 2016 at 14:37 hootsmctoots84hootsmctoots84 2111 gold badge2 silver badges5 bronze badges 6
  • 1 Possibly: codex.wordpress/Function_Reference/… – jdm2112 Commented Oct 11, 2016 at 14:58
  • Have you tried saving / re-saving the permalinks preferences page so the redirects are re-generated? – tillinberlin Commented Oct 11, 2016 at 15:10
  • 1 For me WP has worked this way as long as I can remember (well, for real at least a year or two now). So domain/xxx... redirects to post for what xxx... is closest for. edit: If you had a page which url would be example/jo I don't think it would redirect you anywhere though... I don't see what's the problem here.. – jimihenrik Commented Oct 11, 2016 at 15:22
  • @jimihenrik - I've got quite a few sites on WP and none of them ever seem to redirect based on a partial match of the slug (just tried it now). This is issue is happening on a site built by somebody else. – hootsmctoots84 Commented Oct 11, 2016 at 15:43
  • @jimihenrik - Actually just noticed this happens on one of my sites, but only on a custom post. It doesn't happen on a different site, even if the URL is only off by one character. Very weird. – hootsmctoots84 Commented Oct 11, 2016 at 16:22
 |  Show 1 more comment

1 Answer 1

Reset to default 1

Add this code in your active theme's functions.php file and it should stop Wordpress guessing the source of the incomplete slug:

function no_redirect_guess_404_permalink( $header ){
    global $wp_query;

    if( is_404() )
        unset( $wp_query->query_vars['name'] );

    return $header;
}

add_filter( 'status_header', 'no_redirect_guess_404_permalink' );

Original answer here

Post a comment

comment list (0)

  1. No comments so far