Based on the comments of @Milo and using the rewrite analyzer plugin I found what I understand as a conflict in the rewrite rules?. The following url:
exams/high-school/city-name/subject/math/
matches the following rules
Pattern:
(.?.+?)/page/?([0-9]{1,})/?$
Subtitution:
pagename: exams/high-school/city-name/subject/math
paged: 1
Pattern:
(.?.+?)(/[0-9]+)?/?$
Subtitution:
pagename: exams/high-school/city-name/subject/math/page
page: /1
Pattern:
exams/([^/]+)/([^/]+)/subject/([^/]+)/?$
Subtitution:
pagename: examns
level: high-school
city: city-name
subject: math
page: 1
The last one is the one I’m trying to create. I’m not an expert in the rewriting rules but I think the second one was activating first and producing the wrong redirection to http://www.example.com/exams/1 or http://www.example.com/exams/2
.
So, I changed the second of my rules to:
exams/([^/]+)/([^/]+)/subject/([^/]+)/page/?([0-9]{1,})/?$' => 'index.php?pagename=exams&level=$matches[1]&city=$matches[2]&subject=$matches[3]&pages=$matches[4]
Note the var as ‘pages‘ in plural. It’s working properly. However, the rewrite analyzer plugin is not detecting my rules. ‘?’
In fact, if I change ‘page’ by ‘pages’ or ‘whateverIwant‘ and register that varname and getting it in my plugin:
$args = array( 'post_type' => 'attachment',
'posts_per_page' => 2,
'paged' => ( get_query_var('whateverIwant') ? get_query_var('whateverIwant') : 1 ),
'orderby' => 'post_title',
'order' => 'ASC',
'post_status' =>'published'
);
Also work!. So, the first set of rules I created was in conflict with something inside wordpress. I have much to learn.
PS: I will accept any question with a solid argument solving this problem.