WordPress.org

Ready to get started?Download WordPress

Forums

query string to pretty permalink (1 post)

  1. impolex
    Member
    Posted 1 year ago #

    I'm accessing a Mysql second database inside WordPress and passing values (via a drop down form) with GET within my index.php page to grab fields from this second database. I need to be able to have these queries turn into pretty permalinks.

    I've been able to use the WP_Rewrite api to convert pretty permalinks into a query values:

    Example:
    http://www.zacharybrady.com/text/wordpress/test/2/

    However I now need to turn the queries into pretty permalinks. In other words I never want the visitors to see the queries in the URL.

    My code for the WP_Rewrite is:

    /*REWRITING*/
    
    	function wptuts_add_rewrite_rules() {
    		add_rewrite_rule('([^/]+)/([0-9]+)','index.php?type=$matches[1]&tid=$matches[2]','top');
    	}
    	add_action( 'init', 'wptuts_add_rewrite_rules' );
    
    		function wptuts_register_rewrite_tag() {
    		add_rewrite_tag( '%tid%', '^([0-9]+)$');
    	}
    	add_action( 'init', 'wptuts_register_rewrite_tag');
    
    		function wp_tuts_filter_post_link( $permalink, $post ) {
    
    		// Check if the %eventdate% tag is present in the url:
    		if ( false === strpos( $permalink, '%tid%' ) ){
    				return $permalink;
    				}
    
    			$id = get_query_var('tid');	
    
    			 $permalink = str_replace( '%tid%', $id , $permalink ); 
    
    			  return $permalink;
    	}
    	add_filter( 'post_link', 'wp_tuts_filter_post_link');
    
    	function wptuts2_register_rewrite_tag() {
    		add_rewrite_tag( '%type%', '([^/]+)');
    	}
    	add_action( 'init', 'wptuts2_register_rewrite_tag');
    
    		function wp_tuts2_filter_post_link( $permalink, $post ) {
    
    		// Check if the %eventdate% tag is present in the url:
    		if ( false === strpos( $permalink, '%type%' ) ){
    				return $permalink;
    				}
    
    			$type = get_query_var('type');	
    
    			 $permalink = str_replace( '%type%', $type , $permalink ); 
    
    			  return $permalink;
    	}
    	add_filter( 'post_link', 'wp_tuts2_filter_post_link');

Topic Closed

This topic has been closed to new replies.

About this Topic