WordPress permalinks and passing custom Variables to it
Sometimes we need a simple way of passing a custom variable(s) to WordPress. WordPress has a organised way in this respect as it passes a lot of arguments in URL, so unless you want to grub around directly with the $_GET array, then this solution is a little more elegant. First look at the code: function add_query_vars($aVars) { $aVars[] = "myVar"; // represents the name of the custom variable you want to add in URL return $aVars; } add_filter('query_vars', 'add_query_vars'); function add_rewrite_rules($aRules) { $aNewRules = array('mypage/([^/]+)/?$' => 'index.php?pagename=mypage&myVar=$matches[1]'); $aRules = $aNewRules + $aRules; return $aRules; } add_filter('rewrite_rules_array', 'add_rewrite_rules'); Explanation: function add_query_vars($aVars) { $aVars[] = "myVar"; // represents the name of the custom variable you want to add in URL return $aVars; } add_filter('query_vars', 'add_query_vars'); This function tells wordpress that we…

