permalinks – Custom post type posts auto redirects me to rewritten URLs

Question

I have a custom post type named movies and in archive-movies.php (sample.com/movies/) I’m displaying a directory or list of movies and it has the alphabetical pagination, the alphabetical pagination is achieved by creating a custom taxonomy movies_alphabet under my custom post type movies.

In order to achieve that I used add_rewrite_rule() to rewrote url of my custom taxonomy from sample.com/alphabet/a to sample.com/movies/a here’s my code below.

add_rewrite_rule(
  "^movies/([a-z])/?",
  "index.php?taxonomy=movies_alphabet&term=$matches[1]",
  "top"
);

And now that I’ve successfully rewrote urls with it, everytime I visit a post from my custom post type movies it redirects me to the alphabetical pagination. Sample scenario below

  • sample.com/movies/aquaman redirects to sample.com/movies/a
  • sample.com/movies/bumblebee redirects to sample.com/movies/b
  • sample.com/movies/interstellar redirects to sample.com/movies/i

I’ve tried putting this code below to my functions.php and still didn’t fix the issue.

add_filter('do_redirect_guess_404_permalink', '__return_false'); 

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

0
agent abstract 2 months 2023-02-02T22:36:24-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse