WordPress url incomplete redirects to first article with that name

Stop URL Guessing – Method 1

The first way to stop WordPress from guessing URLs is to use the below code. To do that, open up your theme’s functions.php file.

Once opened, copy and paste the below code and reupload the file.

remove_filter('template_redirect', 'redirect_canonical');

That’s all there is to do. From this point forward, WordPress no longer tries to guess the URL and issues a 404 Not Found error.

Once thing to keep in mind while using the above code is that it completely disables the canonical redirection, which is pretty helpful in terms of SEO.

Stop URL Guessing – Method 2

If you want more SEO friendly way to stop WordPress from guessing URLs. i.e, without completely disabling the redirect_canonical filter, then use the below code.

Simply copy and paste the below code in your theme’s functions.php file or the site-specific plugin and you are good to go.

add_filter('redirect_canonical', 'bs_no_redirect_404');
function bs_no_redirect_404($redirect_url)
{
    if (is_404()) {
        return false;
    }
    return $redirect_url;
}

To be fair, I found this on google some time back and this is the link:
https://www.bloggersignal.com/stop-wordpress-from-guessing-urls/