I have a custom post type i.e services & custom taxonomy services_type

I have custom permalink structure as /%category%/%postname%

term1,term2,term3 are different terms under services_type taxonomy & post1,post2,post3,post4 are posts

I i am trying to acheive is the permalinks as


but right now they are as http://example.com/services/post1

Following is what i have used so far

function wpt_services_posttype() {
  register_post_type( 'services',
        'labels' => array(
        'name' => __( 'Services' ),

      'public' => true,
      'supports' => array( 'title','editor','thumbnail','page-attributes','custom-fields'),
      'capability_type' => 'post',
      'rewrite' => array("slug" => "services/%services_type%"), // Permalinks format
      'menu_position' => 6,         

add_action( 'init', 'wpt_services_posttype' );

//code for adding texonomy
function services_init() {
  // create a new taxonomy
      'labels' => array(
              'name'=>'services type',
              'add_new_item'=>'Add New type ',
              'new_item_name'=>"New type" ,


      'show_ui' => true,
      'show_tagcloud' => false,
            'hierarchical' => true,
      'rewrite' => array( 'slug' => 'services' ),

add_action( 'init', 'services_init' );

add_filter('post_type_link', 'services_permalink_structure', 10, 4);
function services_permalink_structure($post_link, $post, $leavename, $sample)
    if ( false !== strpos( $post_link, '%services_type%' ) ) {
        $service_type_term = get_the_terms( $post->ID, 'service_type' );
        $post_link = str_replace( '%services_type%', array_pop( $service_type_term )->slug, $post_link );
    return $post_link;

I have tried various codes but it i am not getting any closer.

Please help


Yes, any of those are possible and configurable under Settings > Permalinks. Have a look at the Permalinks page for other possibilities.


Hope this will help you.

  • ya i have custom permalinks structure same as you told
    – terminator
    Jan 5 '16 at 9:56
  • try this /%category%/%post_id% /%category%/%post_id%/%postname% Jan 5 '16 at 9:58
  • One thing to note though, it's suggested to add a number at the beginning of your permalinks to reduce the number of rewrite rules WordPress has to generate to resolve all of your URLs. Jan 5 '16 at 10:00
  • no that doesn't do anything,, anyways thanks for trying to help
    – terminator
    Jan 5 '16 at 10:50

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.