2

I need some help about Custom permalinks for custom post types.

I have created a custom post type called "evento" and 3 custom fields for storing date, month and year of the events.

I would like to have a permalinks structure like this:

/eventos/2012/07/30

... where the standard structure would be:

/?post_type=evento&ano=2012&mes=07&dia=30

How to make this magic happen in WordPress? I do not know much about .Htaccess =(

Thanks in advance!!!

  • Have you searched the site? Resp. rewrite-rules, url-rewriting and htaccess? – kaiser Jul 31 '12 at 18:42
  • Yes, but found nothing very explanatory or that I could understand. Thank you. – Miriam de Paula Jul 31 '12 at 19:12
  • 1
    Please add what you've already tried so far and show us your research effort. Thanks. – kaiser Jul 31 '12 at 19:28
  • @kaiser How could I fix my pagination issue? – Miriam de Paula Jul 31 '12 at 23:05
  • Please add this as solution (you can mark it as answer in two days). Then go and open a follow up question about your pagination issue (link in there to this question). One question per question :) – kaiser Jul 31 '12 at 23:52
2

Problem solved!!!! =)

add_action('init', 'evento_add_rewrite_rules');
function evento_add_rewrite_rules( $wp_rewrite ){
    // Add day archive (and pagination)
    add_rewrite_rule("eventos/([0-9]{4})/([0-9]{2})/([0-9]{2})/page/?([0-9]{1,})/?",'index.php?post_type=evento&ano=$matches[1]&mes=$matches[2]&dia=$matches[3]&paged=$matches[4]','top');
    add_rewrite_rule("eventos/([0-9]{4})/([0-9]{2})/([0-9]{2})/?",'index.php?post_type=evento&ano=$matches[1]&mes=$matches[2]&dia=$matches[3]','top');

    // Add month archive (and pagination)
    add_rewrite_rule("eventos/([0-9]{4})/([0-9]{2})/page/?([0-9]{1,})/?",'index.php?post_type=evento&ano=$matches[1]&mes=$matches[2]&paged=$matches[3]','top');
    add_rewrite_rule("eventos/([0-9]{4})/([0-9]{2})/?",'index.php?post_type=evento&ano=$matches[1]&mes=$matches[2]','top');

    // Add year archive (and pagination)
    add_rewrite_rule("eventos/([0-9]{4})/page/?([0-9]{1,})/?",'index.php?post_type=evento&ano=$matches[1]&paged=$matches[2]','top');
    add_rewrite_rule("eventos/([0-9]{4})/?",'index.php?post_type=evento&ano=$matches[1]','top');
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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