query string to pretty permalink
-
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:
https://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');
- The topic ‘query string to pretty permalink’ is closed to new replies.