Forums

conditional rewrite rules (4 posts)

  1. vsandvold
    Member
    Posted 1 year ago #

    Hi,

    got a question about filtering url rewrite rules.

    I'm implementing a music-oriented website on Wordpress, and got posts in the following categories:
    * Concerts
    * Venues
    * Blog

    I want different rewrite rules for each category, eg:
    * /concerts
    * /concerts/2007/12/09/concert+post+title
    * /venues
    * /venues/venue+post+title
    * /blog
    * /blog/2007/12/09/blog+post+title

    Note that no date is displayed for venue posts.

    Any help on how to implement this in Wordpress is highly appreciated.

    These pages contains some information on implementing custom rewrite rules, but I can't find the exact information I'm looking for:
    * http://codex.wordpress.org/Function_Reference/WP_Rewrite
    * http://codex.wordpress.org/Custom_Queries#Permalinks_for_Custom_Archives

    Regards,
    Vegard

  2. vsandvold
    Member
    Posted 1 year ago #

    So far I tried the following, without getting what I want:

    add_filter('rewrite_rules_array', 'my_rewrite');
    function my_rewrite($rewrite) {
    	global $wp_rewrite;
    
       	$category_rules = array(
            	'concerts/' => 'category/concerts/',
            	'venues/' => 'category/venues/'
        	);
    
    	$concert_post_structure = $wp_rewrite->root . "concerts/%year%/%monthnum%/%day%/%postname%/";
    	$venue_post_structure   = $wp_rewrite->root . "venues/%postname%/";
    
    	return ( $rewrite
    		+ $category_rules
    		+ $wp_rewrite->generate_rewrite_rules($concert_post_structure)
    		+ $wp_rewrite->generate_rewrite_rules($venue_post_structure)
    	);
    }
  3. vsandvold
    Member
    Posted 1 year ago #

    What I get is this:
    * concerts/ and venues/ don't work
    * concerts/year/month/day/postname shows all concerts, what I would like concerts/ to do
    * Same for venues/

  4. vsandvold
    Member
    Posted 1 year ago #

    Any help is appreciated, guys.

Topic Closed

This topic has been closed to new replies.

About this Topic