We recently transferred from a customized post type to a standard post type based site. The moving was based on the fact that custom post types may cause issues when mixing reviews and posts within a traditional feed. The custom post type also gave us several issues when trying to do list articles, posts etc.
Now here is where the problem arose. Because the custom post type had a permalink structure of:
site.com/reviews/post
Now since we are moving to a post based structure, all the reviews will break links and we want to keep the permalink structure.
Here is the issue, the code we have now caused it so we can not edit the permalink, it also breaks AMP support since the amp pages are site.com/link/amp but because of this permalink rule, this breaks for those pages.
The current code is as so:
add_filter( 'post_link', 'change_links', 10, 2 );
function change_links( $link, $post) {
if ( $post->post_type == 'post' && in_category( array( 'anime-reviews', 'board-game-reviews', 'book-reviews', 'comic-reviews', 'game-reviews', 'hardware-reviews', 'moviereviews','music-reviews', 'tv-reviews' ) ) ) {
$link = trailingslashit( home_url('/reviews/' . $post->post_name ) );
}
return $link;
}
add_action( 'init', 'reviews_rewrite_rule', 5);
function reviews_rewrite_rule() {
add_rewrite_rule( '^reviews/([^/]+)/?', 'index.php? post_type=posts&name=$matches[1]', 'top' );
}
If anyone has an idea how to solve this issue that would be amazing. Open to any and all ideas!