Custom url for custom post types

Is it possible to create a custom url for custom post types in wordpress?.

I have a directory website where in user can post or add a listing in many cities, i have a custom post type name ads. And all of the ads post titles are phone numbers. So when i create a new ads post in a city (e.g. Birmingham AL), the city will be save as a post meta post_ads_city,

Read More

Automatically the url will be mysite.com/ads/123-123-1234

is it possible to make the url slug based on the city where the ads is posted? so it will be like this:

mysite.com/birmingham-al/123-123-1234 (if the postmeta “post_ads_city”
= “Birmingham AL”) mysite.com/las-vegas/123-123-1234 (if the postmeta “post_ads_city” = “Las Vegas”)

thanks alot.

Related posts

Leave a Reply

1 comment

  1. You will need to change where you registered your custom post type to support rewrites. Your city should be a taxonomy.

    I do believe this is the proper array for this:

     'rewrite'  => array(
                    'slug'          => '',
                    'with_front'    => true
    ),
    

    You will have to regenerate permalinks after (turn off then back on).