my code is like that:

function add_rewrites(){
    add_rewrite_rule(
        '^my_post_type/([^/]*)/([^/]*)/?',
        'index.php?post_type=my_post_type&name=$matches[1]&sub_pages=$matches[2]',
        'top'
    );
 }
add_action( 'init', 'add_rewrites' );

function add_custom_query_var( $vars ){ 
$vars[] = "sub_pages"; 
return $vars; 
} 
add_filter( 'query_vars', 'add_custom_query_var' );

My question is:
http://example.com/$my_post_type/$post/$sub_pages is my link.
How can I filter this $sub_pages with functions.
If I have to filter it in my post page how can I redirect if $sub_pages does not exists.
sorry for my english.

Read more here: How can I filter variables of query_vars?


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.


Wordpress related questions and answers: