theme development - Get taxonomy link with post type slug prefix

I have changed my post type URL structure to have the taxonomy type in the URL as well by doing this:In register_post_ty

I have changed my post type URL structure to have the taxonomy type in the URL as well by doing this:

In register_post_type (Post type: release):

'rewrite' => array('slug' => __('releases/%type%', 'mytheme'), 'with_front' => false),

In functions.php

function wpa_show_permalinks( $post_link, $post ){
  if ( is_object( $post ) && $post->post_type == 'release' ){
      $terms = wp_get_object_terms( $post->ID, 'type' );
      if( $terms ){
          return str_replace( '%type%' , $terms[0]->slug , $post_link );
      }
  }
  return $post_link;
}
add_filter( 'post_type_link', 'wpa_show_permalinks', 1, 2 );

When I loop through the available types in my I need to generate the correct permalink for example /releases/movies/ but when I loop through get_terms and display the link like this:

get_term_link($releaseType)

it returns /types/movies. What would be the most elegant way to release the URL with the post type. I wanna avoid writing the urls hardcoded in case it changes.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745249101a4618567.html

相关推荐

  • theme development - Get taxonomy link with post type slug prefix

    I have changed my post type URL structure to have the taxonomy type in the URL as well by doing this:In register_post_ty

    6小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信