Change URL of category using add_rewrite_rule method in wordpress

1.2k views Asked by At

Hi i have custom post type called "downloads" and custom taxonomy called "download_category" so when i am open any category page like i have one category call "Avro" so

current URL of page is http://domainname/downloads/category/avro/now i want to remove keyword call 'category' from URL and want to change 'Download' key word to "Gallery"

so i have written following URL redirecting rule add_rewrite_rule('^gallery/(/(.*))/?$','index.php?download_category=$matches[1]','top');

but problem is when i am opening sub category of main category it will always load parent category page For e.g there is category call "lancaster" which child of "Avro" so that when i am opening http://aviationimages.ky/gallery/avro/lancaster/ it will show page for "Avro" not for "lancaster"

Please help Thanks in advance

1

There are 1 answers

0
cjquinn On

The rewrite rule isn't passing the correct part of the url to download_category.

Try something like:

add_rewrite_rule('^gallery/(.+?)/(.+?)/?$', index.php?download_category=$matches[2]', 'top')

You would still need the other rewrite rule, or something similar, for all the parent categories.