• Resolved regicide

    (@regicide)


    good day everyone!!

    i got this code here on the forum and it’s working fine.

    add_filter('rewrite_rules_array','my_insert_rewrite_rules');
    			add_filter('query_vars','my_insert_query_vars');
    			add_action('wp_loaded','my_flush_rules');
    
    			// flush_rules() if our rules are not yet included
    			function my_flush_rules(){
    				$rules = get_option('rewrite_rules');
    
    				if(!isset($rules['(whats-new)/page-(\d*)$']) || !isset($rules['(whats-new)/page-(\d*)/(\d*)$'])){
    					global $wp_rewrite;
    					$wp_rewrite->flush_rules();
    				}
    			}
    
    			// Adding a new rule
    			function my_insert_rewrite_rules($rules)
    			{
    				$newrules = array();
    				$newrules['(whats-new)/page-(\d*)/?$'] = 'index.php?pagename=$matches[1]&param1=$matches[2]';
    				return $newrules + $rules;
    			}
    
    			// Adding the id var so that WP recognizes it
    			function my_insert_query_vars($vars)
    			{
    				array_push($vars, 'param1');
    				return $vars;
    			}

    my problem is, i want to have multiple parameters and i don’t know how.

    i already tried this one but it’s not working fine.

    add_filter('rewrite_rules_array','my_insert_rewrite_rules');
    			add_filter('query_vars','my_insert_query_vars');
    			add_action('wp_loaded','my_flush_rules');
    
    			// flush_rules() if our rules are not yet included
    			function my_flush_rules(){
    				$rules = get_option('rewrite_rules');
    
    				if(!isset($rules['(whats-new)/page-(\d*)$']) || !isset($rules['(whats-new)/page-(\d*)/(\d*)$'])){
    					global $wp_rewrite;
    					$wp_rewrite->flush_rules();
    				}
    			}
    
    			// Adding a new rule
    			function my_insert_rewrite_rules($rules)
    			{
    				$newrules = array();
    				$newrules['(whats-new)/page-(\d*)/?$'] = 'index.php?pagename=$matches[1]&param1=$matches[2]';
    				$newrules['(whats-new)/page-(\d*)/(\d*)/?$'] = 'index.php?pagename=$matches[1]&param1=$matches[2]&param2=$matches[3]';
    				return $newrules + $rules;
    			}
    
    			// Adding the id var so that WP recognizes it
    			function my_insert_query_vars($vars)
    			{
    				//$vars[] = 'param1';
    				//$vars[] = 'param2';
    				array_push($vars, 'param1');
    				array_push($vars, 'param2');
    				return $vars;
    			}

    thank you in advance!!
    more powers,.

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘custom rewrite’ is closed to new replies.