title: WordPress Custom Type append Post ID at the end
body: <p>I've been searching for two days know and tried almost every example I've seen online but the real problem is that all examples have different post-type-names or want different results in general.</p>
  
  <p>That's why I want to ask for help and start from scratch.</p>
  
  <p>I've created a Custom Post Type for listing some Jobs opportunities but because most job-titles have the same name (product designer) I would like to prevent WordPress from adding -1, -2, -3, -4 after each slug over time and that's why I was thinking about adding the %post_id% behind the %post-name% for only this new custom post type.
  A post_id should be an unique number so that would prevent ugly urls in the long run.</p>
  
  <p>This is what I have, only the post type setup, but right now I think I need to work with rewrites and stuff.</p>
  
  <pre><code>    function jobs() {
  
      $labels = array(
          'name'                =&gt; _x( 'Jobs', 'Post Type General Name', 'theme-name' ),
          'singular_name'       =&gt; _x( 'Job', 'Post Type Singular Name', 'theme-name' ),
          'menu_name'           =&gt; __( 'Jobs', 'theme-name' ),
          'parent_item_colon'   =&gt; __( 'Parent Job:', 'theme-name' ),
          'all_items'           =&gt; __( 'All Jobs', 'theme-name' ),
          'view_item'           =&gt; __( 'View Job', 'theme-name' ),
          'add_new_item'        =&gt; __( 'Add New Job', 'theme-name' ),
          'add_new'             =&gt; __( 'Add New', 'theme-name' ),
          'edit_item'           =&gt; __( 'Edit Job', 'theme-name' ),
          'update_item'         =&gt; __( 'Update Job', 'theme-name' ),
          'search_items'        =&gt; __( 'Search Job', 'theme-name' ),
          'not_found'           =&gt; __( 'Not found', 'theme-name' ),
          'not_found_in_trash'  =&gt; __( 'Not found in Trash', 'theme-name' ),
      );
      $rewrite = array(
          'slug'                =&gt; 'vacatures',
          'with_front'          =&gt; false,
          'pages'               =&gt; false,
          'feeds'               =&gt; false,
      );
      $args = array(
          'label'               =&gt; __( 'vacatures', 'theme-name' ),
          'description'         =&gt; __( 'Post Type Description', 'theme-name' ),
          'labels'              =&gt; $labels,
          'supports'            =&gt; array( 'title', 'editor', 'thumbnail', 'revisions', 'custom-fields', ),
          'taxonomies'          =&gt; array( 'category' ),
          'hierarchical'        =&gt; false,
          'public'              =&gt; true,
          'show_ui'             =&gt; true,
          'show_in_menu'        =&gt; true,
          'show_in_nav_menus'   =&gt; false,
          'show_in_admin_bar'   =&gt; false,
          'menu_position'       =&gt; 9,
          'menu_icon'           =&gt; 'dashicons-welcome-learn-more',
          'can_export'          =&gt; true,
          'has_archive'         =&gt; true,
          'exclude_from_search' =&gt; false,
          'publicly_queryable'  =&gt; true,
          'rewrite'             =&gt; $rewrite,
          'capability_type'     =&gt; 'post',
      );
      register_post_type( 'vacatures', $args );
  
  }
  // Hook into the 'init' action
  add_action( 'init', 'jobs', 0 );
  </code></pre>
  
  <p>any help would be so thankful!</p>
  
  <h1>EDIT</h1>
  
  <p>I'm a bit further now and I have a feeling I'm getting close to what I need.</p>
  
  <p>I've added the code below and the result is almost good. It appends the post_id on the end of the slug only problem it's twice/double.</p>
  
  <p>I want this:</p>
  
  <p><a href="http://example.com/vacatures/product-designer/123/" rel="nofollow">http://example.com/vacatures/product-designer/123/</a></p>
  
  <p>But instead it does this:</p>
  
  <p><a href="http://example.com/vacatures/product-designer/123/123/" rel="nofollow">http://example.com/vacatures/product-designer/123/123/</a></p>
  
  <pre><code>function fix_permalink( $post_link, $id = 0 ) {
  
      add_rewrite_rule(
          '^vacatures/',
          'index.php?post_type=vacatures&amp;p=',
          'top'
      );
  
      $post = get_post($id);
      if ( is_wp_error($post) || $post-&gt;post_type != 'vacatures' ) {
          return $post_link;
      }
  
      empty ( $post-&gt;slug )
          and $post-&gt;slug = sanitize_title_with_dashes( $post-&gt;post_title );
  
      return home_url( user_trailingslashit( "vacatures/$post-&gt;slug/$post-&gt;ID" ) );
  
  }
  add_filter( 'post_type_link', 'fix_permalink' );
  </code></pre>