WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a custom post type "contest_recipe". I can view contest recipe posts by year and by date with the following urls:

http://example.com/2011/?post_type=contest_recipe - shows all 2011 contest recipes
http://example.com/2011/7/?post_type=contest_recipe - shows all July 2011 contest recipes

I would like to simplify the url to


Is this possible? I am not familiar with the rewrite rules concept. Can anyone recommend a tutorial on how to learn about this or provide an example?

share|improve this question

I used this to enable yearly and monthly archive for custom post type. Just drop in this code into your functions.php file.

This will add your custom rule right on the top of the Rules array. NB - Wordpress uses rules array to store rewrite rules.

        function wpse22992_custom_post_rewrite( $rewrite_rules ) {

                $cpslug = 'contest_recipe'; // custom post type slug

                // Rule to display monthly archive -> contest_recipe/2012/08/
                $year_archive = array( $cpslug . '/([0-9]{4})/([0-9]{1,2})/?$' => 'index.php?year=$matches[1]&monthnum=$matches[2]&post_type=' . $cpslug );

                // Rule to display yearly archive -> contest_recipe/2012/
                $month_archive = array( $cpslug . '/([0-9]{4})/?$' => 'index.php?year=$matches[1]&post_type=' . $cpslug );

                $rewrite_rules = $year_archive + $month_archive + $rewrite_rules;

                return $rewrite_rules;


        add_filter('rewrite_rules_array', 'wpse22992_custom_post_rewrite');

Resource -

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.