admin管理员组

文章数量:1025235

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

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

本文标签: permalinksWordPress Custom Post Type is Matching on Partial Slug