When you enable pagination for comments in wordpress the typical pagination page for a comment is “comment-page-1” “comment-page-2” etc. what I want is this to appear like “review-page-1” “review-page-2” etc. (I am using comments for a reviews)
Somehow I have managed to accomplish this but there is one weird behaviour that I can’t seem to understand.
Here is how I have accomplished this.
basically what I did is wrote a custom url rewrite which matches to the default comment pagination url.
add_filter( 'rewrite_rules_array','my_insert_rewrite_rules_two' );
add_action( 'wp_loaded','my_flush_rules_two' );
// flush_rules() if our rules are not yet included
function my_flush_rules_two(){
$rules = get_option( 'rewrite_rules' );
if ( ! isset( $rules['^([^/]*)/([^/]*)/review-page/([^/]*)'] ) ) {
global $wp_rewrite;
$wp_rewrite->flush_rules();
}
}
// Adding a new rule
function my_insert_rewrite_rules_two( $rules )
{
$newrulesone = array();
$newrulesone['^([^/]*)/([^/]*)/review-page/([0-9]{1,})'] ='index.php?name=$matches[2]&cpage=$matches[3]';
return $newrulesone + $rules;
}
I know I should not use wp_loaded but this is just for the testing purpose.So now whenever someone visit
mywebsite.com/my_product_category/my_product_name/review-page/12
it matches to
index.php?name=product_name&cpage=12
Comment loads and everything works if I change number to something else it also does work. but every time I load the page it automatically appends /comment-page-#/ i.e
if I try to load
mywebsite.com/my_product_category/my_product_name/review-page/12
the url in the browser changes to
mywebsite.com/my_product_category/my_product_name/review-page/12/comment-page-12/#reviews
Here is how I generated the pagination links in my templates comment.php
$args = array(
'base' => get_permalink().'review-page/'.'%#%',
'add_fragment' => '#reviews' );
paginate_comments_links($args);
does anyone has ever tried something like this before. what am I doing wrong here ? is there another way ? or am doing it totally wrong ? Need help desperately.