0

I am rewriting the URLs for a custom post type as follows:

In my register_post_type code I have:

'rewrite' => array(
    'slug' => 'magazine/%magazine_categories%',
    'feeds' => false,
    'with_front' => true
),

In my functions.php file I have:

add_filter('post_type_link', 'magazine_permalink_structure', 10, 2);
function magazine_permalink_structure($post_link, $post){
    if(false !== strpos($post_link, '%magazine_categories%')){
        $taxonomy_terms = get_the_terms($post->ID, 'magazine_categories');
        foreach($taxonomy_terms as $term){ 
            if(!$term->parent){
                $post_link = str_replace('%magazine_categories%', $term->slug, $post_link);
            }
        }
    }
    return $post_link;
}

and

add_action('generate_rewrite_rules', 'magazine_rewrite_rules');
function magazine_rewrite_rules($wp_rewrite){
    $new_rules = array( 
        'magazine/([^/]+)/page/(\d+)/?$' => 'index.php?magazine_categories='.$wp_rewrite->preg_index(1).'&paged='.$wp_rewrite->preg_index(2),
    );
    $wp_rewrite->rules = $new_rules + $wp_rewrite->rules;
}

This all works fine and all my taxonomy term archive pages are working fine and the single post pages are working fine too.

However, what is not working in the RSS Feed URL. When I try to access the Feed URL for a term, it redirects me to an article that has the word "feeding" as part of the article slug.

I thought I might need to write a specific re-write rule for URLs that have /feed/ in them to direct them to the RSS feed, so I tried adding this re-write rule to my magazine_rewrite_rules function:

'magazine/feed/([^/]+)/' => 'index.php?post_type=magazine_articles&magazine_categories='.$wp_rewrite->preg_index(1).'&feed=rss2',

This did not help at all. I was careful to re-generate my permalinks etc after making this tweak and it definitely did not help.

Not really sure how to work around the problem at this point so would appreciate any assistance.

Your Answer

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

Browse other questions tagged or ask your own question.