Right url for custom post type

Question

I have custom post type called news2, and its url is land/news2. The archive page url is working well but how can I set my taxonomy page and single page right

// Change custom post type permalinks
function news2_links($post_link, $post = 0) {
$terms = wp_get_object_terms( $post->ID, 'news2cat' );
  if($post->post_type === 'news2') {
      return home_url('news2/' . $terms[0]->slug . '/' . $post->ID . '/');
  }
  else{
      return $post_link;
  }
}
add_filter('post_type_link', 'news2_links', 1, 3);

// Get the Post ID from permalink structure base/CT/Post_ID
function news2_rewrites_init($post_link, $post = 0){
  //add_rewrite_rule('news2/.*/([0-9]+)?$', 'index.php?post_type=news2&p=$matches[1]', 'top');
  add_rewrite_rule('news2/([A-Za-z0-9]+)?/([0-9]+)?(page/)?([0-9]+)?/?$', 'index.php?paged=$matches[4]&post_type=news2&news2cat=$matches[1]&p=$matches[2]', 'top');
}
add_action('init', 'news2_rewrites_init');
0
, Fernando Souza 3 years 2020-03-31T00:51:15-05:00 0 Answers 79 views 0

Leave an answer

Browse
Browse