Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save vishalarora91/1ba8673a6988e9d4004e47a4bc3a7a10 to your computer and use it in GitHub Desktop.
Save vishalarora91/1ba8673a6988e9d4004e47a4bc3a7a10 to your computer and use it in GitHub Desktop.
// media_coverages = Post Type
function media_coverages_rewrite_rules(){
// For year and month
add_rewrite_rule(
'media_coverages/([0-9]{4})/([0-9]{1,2})/?$',
'index.php?post_type=media_coverages&year=$matches[1]&monthnum=$matches[2]',
'top'
);
// For year
add_rewrite_rule(
'media_coverages/([0-9]{4})/?$',
'index.php?post_type=media_coverages&year=$matches[1]',
'top'
);
// For pagination
add_rewrite_rule(
'media_coverages/([0-9]{4})/page/([0-9]{1,2})/?$',
'index.php?paged=$matches[2]&post_type=media_coverages&year=$matches[1]',
'top'
);
}
add_action( 'init', 'media_coverages_rewrite_rules' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment