php - Profile Query Submit -
i have following code:
<?php $id=$_get['id'];$id=str_replace('_',' ',$id); global $wpdb; $res = $wpdb->get_results("select * `agents` `name`='".$id."'"); foreach ($res $row) { $name = $row->name; echo $name; } ?>
when hit submit profiles display following url: http://www.website.com/profile/?id=first_last
is there way display url this: http://www.website.com/profile/first-last/
thank you,
john
you can use htaccess rewriting
# begin wordpress <ifmodule mod_rewrite.c> rewriteengine on rewritebase / rewriterule ^profile/(.*) /profile/?id=$1 [l] rewriterule ^index\.php$ - [l] rewritecond %{request_filename} !-f rewritecond %{request_filename} !-d rewriterule . /index.php [l] </ifmodule> # end wordpress
or wordpress page_rewrite_rules:
you can add block of code theme’s functions.php file.
add_filter( 'page_rewrite_rules', 'my_page_rewrite_rules' ); function my_page_rewrite_rules( $rewrite_rules ) { // generic page rewrite rule @ end of array // place our rule 1 before end( $rewrite_rules ); $last_pattern = key( $rewrite_rules ); $last_replacement = array_pop( $rewrite_rules ); $rewrite_rules += array( 'profile/([0-9]+)/?$' => 'index.php?pagename=profile&id=$matches[1]', $last_pattern => $last_replacement, ); return $rewrite_rules; }
wordpress codex: http://codex.wordpress.org/rewrite_api/add_rewrite_rule
documentation: http://www.hongkiat.com/blog/wordpress-url-rewrite/
Comments
Post a Comment