0

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

http://example.com/term1/post1
http://example.com/term1/post2
http://example.com/term2/post3
http://example.com/term3/post4

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',
    array(
        '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,         
      'show_ui'=>true,
      'query_var'=>true

      )
  );
}
add_action( 'init', 'wpt_services_posttype' );

//code for adding texonomy
function services_init() {
  // create a new taxonomy
  register_taxonomy(
    'services_type',
    'services',   
    array(
      '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

0

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

/%category%/%postname%

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% – shiva chauhan 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. – shiva chauhan 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.