Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

WordPress

wordpress add_rewrite_rule issue, i think i am doing this all wrong, help please!

Hi, i am having some struggles with an add rewrite rule, i have tried a lot of combinations and things.

here is the scenario i have a custom post type named community_blog, links to post within it ends like this:

https://mysite.com/community_blog/my-sample-post

i want to be able to access my sample post via https://mysite.com/community_blog/my-sample-post and have the same post to display if the user types https://mysite.com/ca/community_blog/my-sample-post

here is the rewrite rule i am adding but is not working, is just redirecting to https://mysite.com/community_blog/my-sample-post when i try the ca version.

please help, i can get it to work, whats wrong, thank you so much :).

code i am using: add_action('init',function(){ //rewrite add_rewrite_rule('ca/community_blog/([^/?]+)/?$','index.php?community_blog=$matches[1]','top'); flush_rewrite_rules(); });