Did you try to filter the $wp_query object? You can use this code snippet to search for the category slug directly in DB:
function pm_detect_term_slugs($query) {
global $wpdb;
// Do not run when Elementor is opened
if((!empty($_REQUEST['action']) && strpos($_REQUEST['action'], 'elementor') !== false) || isset($_REQUEST['elementor-preview'])) {
return $query;
}
// 1. Get the slug
if(!empty($query['pagename'])) {
$slug = $query['pagename'];
} else if(!empty($query['name'])) {
$slug = $query['name'];
} else if(!empty($query['attachment'])) {
$slug = $query['attachment'];
}
if(!empty($slug)) {
$slug = basename($slug);
// 2. Check if the slug is assigned to any post item
$sql_query = "SELECT t.slug, t.term_id, tt.taxonomy FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy AS tt ON(tt.term_id = tt.term_id) WHERE 1=1 AND slug = %s";
$term = $wpdb->get_row($wpdb->prepare($sql_query, array($slug)));
// 3. Filter the query if any term was found
if(!empty($term->taxonomy)) {
$page = (!empty($query['paged'])) ? $query['paged'] : 1;
$new_query = array(
'term' => $term->slug,
'taxonomy' => $term->taxonomy,
'paged' => $page
);
// 4. Disable canonical redirect
remove_action('template_redirect', 'wp_old_slug_redirect');
remove_action('template_redirect', 'redirect_canonical');
add_filter('wpml_is_redirected', '__return_false', 99, 2);
add_filter('pll_check_canonical_url', '__return_false', 99, 2);
return $new_query;
}
}
return $query;
}
add_filter('request', 'pm_detect_term_slugs', 9999);
Alternatively you can use my plugin Permalink Manager Pro to filter the category permalinks:
https://permalinkmanager.pro/docs/basics/bulk-edit-wordpress-permalinks
.htaccess
file? It would be at the root directory and you might need to change your settings if viewing in an FTP client to "view hidden files." Also, do you have a caching plugin or caching on the server-level?