This may be something simple for most PHP coders, however, I have never had to do this before. I am using Wordpress website with a Page Template. On this page is a page I created to Query results by User_id, then displaying the users profile information. What I am trying to achieve is the following:
Page #1 Lawyers Directory > Has Multiple Lawyers being pulled from Database
Action: Click Link (Example Link: http://example.com/lawyer-profile?user_id=9) *the number 9 is the dynamic number
Page #2 Lawyer Profile > Has Profile Info of Lawyer
PROBLEM How do I change this URL http://example.com/lawyer-profile?user_id=9
TO
http://example.com/lawyer-profile/john-doe/
But still pull the data by using the User_id?
Any help would be appreciated!
UPDATE: I found this on wordpress's website and I modified it to reflect what I would need it to do but it doesn't work. It redirects to the lawyer-directory page which is page_id 189 but still shows the query strings in the URL.
Here is the url i am using: http://example.com/index.php?page_id=189&userid=195&fullname=jack-bowers
and it should look like this: http://example.com/lawyer-directory/jack-bowers/
any suggestions?
function custom_rewrite_tag() {
add_rewrite_tag('%userid%', '([^&]+)');
add_rewrite_tag('%fullname%', '([^&]+)');
}
add_action('init', 'custom_rewrite_tag', 10, 0);
function custom_rewrite_rule() {
add_rewrite_rule('^lawyer-directory/([^/]*)/([^/]*)/?','index.php?page_id=189&userid=$matches[1]&fullname=$matches[2]','top');
}
add_action('init', 'custom_rewrite_rule', 10, 0);
/lawyer-profile/9/john-doe/, where only the9has actual meaning and the rest doesn’t matter) – or rewrite your script to select the data by the value that does get passed instead,john-doe. For that to properly work, the value should be unique within your data set of course.