0

I have a website which lists concerts and festival and some of them are returning each year. I have made a custom taxonomy where you can add the post to a year (2017, 2018, 2019 and so on). I also added the custom taxonomy to the slug (/shows/%archive%/%postname%/ – where archive is the year the post is in).

This works all like it should, URLs are now: /2017/name-of-show or /2018/name-of-festival

But when I re-add a festival for the next years edition I still get the URL with a -2 at the end, because of the post slug is already taken, while it should be /2017/festival-name and /2018/festival-name instead of /2018/festival-name-2

Am I missing something, or is this just not possible to do with duplicate names/slugs?

0

You can do that using Custom Permalinks Plugin, you need to add a full slug manually [shows/2017/any].

It also allow you customize your permalink: [anyname/another/2017/example/slug].

You should still using this plugin, if you deactivate it, all permalinks will return to default [shows/2017/%postname%]

| improve this answer | |
  • I would prefer not use use a plug-in for this, or have to do it manually as there are over 600 posts on the website already. I haven't really thought about this through when I first started the website :( – user129909 Oct 29 '17 at 17:24
  • sorry, but wordpress not allow this. – techno Oct 29 '17 at 17:40
  • Yeah, I've been looking at it all afternoon, but not found what I have been looking for. Going to have to find another solution I guess. To bad, though. – user129909 Oct 29 '17 at 18:18
0

It is easy to manipulate post's slug, before writing it to database. If concerts and festivals occur once a year, you can still use %postname% tag for a permalink. Your URL will look like, for example, http://yoursite.com/2016-concert-name/. Add this code to functions.php:

function wpse_filter_handler($data, $postarr) {
    if(!is_numeric(substr($data['post_name'], 0, 4))) {
        $catids = $postarr['post_category'];
        if(count($catids) > 1) {
            $catobj = get_category($catids[1]);
            $data['post_name'] = $catobj->slug . '-' . $data['post_name'];
        }
    }
    return $data;
}
add_filter( 'wp_insert_post_data', 'wpse_filter_handler', 10, 2 );

This example uses categories, but for custom taxonomies the logic is exactly the same. Of course, additional checks should be included, in code above, depending on your actual settings.

| improve this answer | |
  • Hi Frank, thank you for your reply. I was able to create a function that creates slugs based off ACF input, but I would prefer to use slugs that look like yousite.com/2017/venue/name-of-band. Eventually I was able to create this with the plug-in Custom Permalinks as earlier suggest. – user129909 Oct 31 '17 at 7:31

Your Answer

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