2

I am creating a plugin. I want to pass parameters in URL or you can say I want multiple URLs for same page(But this will load same page Not a Redirect). For example: http://www.ijmsbr.boxysolutions.com/publications-of-ijmsbr/?data=2016-11 I want this URL in this structure http://www.ijmsbr.boxysolutions.com/publications-of-ijmsbr/2016-11/

and these will be multiple links like

  • publications-of-ijmsbr/2016-11/
  • publications-of-ijmsbr/2016-12/
  • publications-of-ijmsbr/2017-01/

But all links should load this one page publications-of-ijmsbr/

http://www.ijmsbr.boxysolutions.com/publications-of-ijmsbr/

this is my custom page. I want to get these parameters (/2016-11/, /2016-12/) on my page.

Muhammad Akif
  • 76
  • 1
  • 6

1 Answers1

3

Resolved


First we'll add filter to set query variables. Remember you've to call flush_rewrite_rules() each time when you'll add new variable in array. Once you've run flush_rewrite_rule function after that you can comment or delete this line.

function themeslug_query_vars( $qvars ) {
$qvars[] = 'jm_volume';
$qvars[] = 'jm_art_id';
$qvars[] = 'jm_author';
//flush_rewrite_rules();
return $qvars;
}
add_filter( 'query_vars', 'themeslug_query_vars' , 10, 1 );

After registration of query variables we can add add_rewrite_rules and assign to our URL like this. Remember to call flush_rewrite_rules() function

function add_rewrite_rules($aRules) {
$aNewRules = array(
    'publications-of-ijmsbr/article/(.*)?' => 'index.php?pagename=publications-of-ijmsbr&jm_art_id=$matches[1]',
    'publications-of-ijmsbr/author/(.*)?' => 'index.php?pagename=publications-of-ijmsbr&jm_author=$matches[1]',
    'publications-of-ijmsbr/(.*)?' => 'index.php?pagename=publications-of-ijmsbr&jm_volume=$matches[1]'
);
$aRules = $aNewRules + $aRules;
//flush_rewrite_rules();
return $aRules;
}
add_filter('rewrite_rules_array', 'add_rewrite_rules');
Muhammad Akif
  • 76
  • 1
  • 6