generate custom permalink based on a custom field

I’m newbie to the WordPress.

So far I have a custom post type called ‘property’. This post type has one custom field called ‘property_city’.

In WP-admin – permalink setting, I have selected Post name option.
So, posts of this custom post type have URLs like:

http://xxx.local/properties/edge-apartments/

http://xxx.local/properties/northgate-point/

What I want to have those URL to be generated using the city of the property and also I want to change properties prefix with student-properties like that:

http://xxx.local/student-properties/Manchester/edge-apartments/

http://xxx.local/student-properties/Chester/northgate-point/

I have tried various plugin and various code, but none of them worked as expected.

Any help would be appreciated.

Thanks,

2 Answers
2

Try this plugin Custom Post Type Permalinks, it allows you to set permalinks for custom post types. If your client does not want additional plugin then this plugin is also available on GitHub you can fork it or include this functionality in your own plugin or your functions.php.

In order to use anything dynamic in the permalink, it has to be a Structure Tag e.g. Custom Taxonomies, Author Name, Date Published, etc.
So you need to have a taxonomy called ‘City’ which you will select while creating the post and then you can use the taxonomy in the Setings->Permalinks ->

%city%/%postname%

Look at this screenshot for a better understanding:
Screenshot of Custom Post Type Permalinks plugin

Leave a Comment