Custom field in query string: change to pretty permalink
-
Hello,
my website is about people and my urls look something like this:mydomain.com/age/45/
mydomain.com/height/176cm/
mydomain.com/birthplace/germany/hamburg/Age, height and birthplace are custom taxonomies, and 45, 176cm and germany/hamburg are taxonomy terms.
Now I use ‘posts_where’ to split these results into men and women by using a custom field “gender” from a custom table “persons”:
add_filter('posts_where', 'gender'); function gender( $where ) { if (is_tax()) { global $wpdb; if (isset($_GET['g'])) { if ($_GET['g'] === 'women') { $where .= " AND gender = 'She' "; } elseif ($_GET['g'] === 'men') { $where .= " AND gender = 'He' "; } } } return $where; }
This works and the URLs look like this:
mydomain.com/age/45/?g=women and mydomain.com/age/45/?g=menBut I would like to use pretty permalinks like this:
mydomain.com/age/45/women/ and mydomain.com/age/45/men/I found some examples with add_rewrite_rule, but it doesn’t seem to work with ‘posts_where’, I always get a message “page not found”. Maybe it’s because I work with custom fields in a custom table?
I would be happy, if someone could help me!
Thank you in advance!
Andreas
- The topic ‘Custom field in query string: change to pretty permalink’ is closed to new replies.