WordPress.org

Ready to get started?Download WordPress

Forums

Retrieving the rewrite rule for a post (1 post)

  1. JsonB123
    Member
    Posted 1 year ago #

    I've generated rewrite rules for my custom post type "press", via the rules below. These are working and I've flushed the cache, etc. My question is how to then retrieve these rules (or just the URL format, I'm not sure?) for my widget that I want to print out the archives for. So instead of printing 2011/?post_type=press it would know to print press/2011/ for this specific post type.

    Is there a function or filter to do that?

    function custom_rewrites() {
    	// Add day archive (and pagination)
    	add_rewrite_rule("press/([0-9]{4})/([0-9]{2})/([0-9]{2})/page/?([0-9]{1,})/?",'index.php?post_type=press&year=$matches[1]&monthnum=$matches[2]&day=$matches[3]&paged=$matches[4]','top');
    	add_rewrite_rule("press/([0-9]{4})/([0-9]{2})/([0-9]{2})/?",'index.php?post_type=press&year=$matches[1]&monthnum=$matches[2]&day=$matches[3]','top');
    
    	// Add month archive (and pagination)
    	add_rewrite_rule("press/([0-9]{4})/([0-9]{2})/page/?([0-9]{1,})/?",'index.php?post_type=press&year=$matches[1]&monthnum=$matches[2]&paged=$matches[3]','top');
    	add_rewrite_rule("press/([0-9]{4})/([0-9]{2})/?",'index.php?post_type=press&year=$matches[1]&monthnum=$matches[2]','top');
    
    	// Add year archive (and pagination)
    	add_rewrite_rule("press/([0-9]{4})/page/?([0-9]{1,})/?",'index.php?post_type=press&year=$matches[1]&paged=$matches[2]','top');
    	add_rewrite_rule("press/([0-9]{4})/?",'index.php?post_type=press&year=$matches[1]','top');
    }
    add_action('init', 'custom_rewrites');

Topic Closed

This topic has been closed to new replies.

About this Topic