I’ve got a question. Maybe it’s something existing and I don’t know the name. Or maybe it’s something custom.
I’ve got a post type for news. The news posts have categories. These are some examples of separate news items
News item 1.
News item 2.
News item 3.
I have 3 pages where I show and filter the news:
Showing a filtered post grid on each news page is not the problem. The problem is displaying them. By default the permalinks of each news post is:
And this is fine for the news on www.domain/news/
But now I want to display the category news items like following: From www.domain/purple/news I want to click on the news item and open it like:
And from www.domain/red/news I want to click on the news item and open it like:
How do I get the news on the category news pages to open and show the items on the preferred url? (this should also show up in the sitemap.xml)
I’ve got a question. Maybe it’s something existing and I don’t know the name. Or maybe it’s something custom.
I’ve got a post type for news. The news posts have categories. These are some examples of separate news items
News item 1.
News item 2.
News item 3.
I have 3 pages where I show and filter the news:
Showing a filtered post grid on each news page is not the problem. The problem is displaying them. By default the permalinks of each news post is:
And this is fine for the news on www.domain/news/
But now I want to display the category news items like following: From www.domain/purple/news I want to click on the news item and open it like:
And from www.domain/red/news I want to click on the news item and open it like:
How do I get the news on the category news pages to open and show the items on the preferred url? (this should also show up in the sitemap.xml)
you can use Custom Permalinks plugin. you can create and edit each post and category link very essay. https://wordpress/plugins/custom-permalinks/ Try this once
I've found a solution. This is the abstracted version:
add_rewrite_rule(
'^red\/news([^/]*)/?',
'index.php?event=$matches[1]',
'top'
);
//Ensure the $wp_rewrite global is loaded
global $wp_rewrite;
//Call flush_rules() as a method of the $wp_rewrite object
$wp_rewrite->flush_rules( false );
In the actual function I've made an array with the pages I want to redirect. (Source and destination) and run foreach and flush the rules after.
example/news/purple/
andexample/news/purple/first-news-slug/
instead? (It's much more natural and intuitive...) – Krzysiek Dróżdż Commented Nov 29, 2018 at 10:58