• Hi! I´ve been trying to make a custom post available under the URL mysite.com/news/year/postname.
    Here is the code I come up with:

    function create_post_types(){
    	$args = array( 'label' => 'News',
    				  'singular_label' => 'News',
    				  'query_var' => true,
    				  'rewrite' => array( 'slug' => 'news/%topic%' ) );
    	register_post_type( 'news', $args );
    
    	$args = array( 'hierarchical' => true,
    		       'label' => 'Topics',
    		       'rewrite' => false,
    		       'query_var' => true );
    	register_taxonomy( 'topic', 'news', $args );
    
    	add_rewrite_tag( '%topic%', '(.+?)', 'post_type=news&topic=' );
    
    	flush_rewrite_rules();
    }
    add_action( 'init', 'create_post_types' );

    But it´s not working. If I try to access the post under the intended URL, it works; but it also works if I enter “asdf” for the category.
    And, the permalinks created read “%topic%/test-post”, so the %topic%-tag doesn´t get replaced.

    Anyone have an idea on what I did wrong?
    Thanks for your help

Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Custom post types & rewrite’ is closed to new replies.