2016-08-02 2 views
0

나는이 문제에 대한 해결책을 찾고, 많은 기사를 읽고, stackoverflow와 다른 곳에서 많은 'fixes'를 시도했지만 성공하지 못했습니다.Wordpress 커스텀 Permalink 사용자 정의 포스트 타입을위한 구조

저는 Wordpress (버전 4.5.3)에서 만든 맞춤 게시물 유형에 대한 퍼머 링크 구조를 만들려고합니다. 게시물 유형을 '동영상'이라고합니다. 기본적으로 내 퍼머 링크는 'http://localhost.wordpress/videos/my-video-post'처럼 보입니다. 링크의 '동영상'을 게시물의 카테고리 이름 (예 : 'http://localhost.wordpress/computer-lessons/my-video-post')으로 대체하고 싶습니다. 카테고리는 '컴퓨터 레슨'입니다. 아래 코드를 사용하여 'http://localhost.wordpress/categories/computer-lessons/my-video-post'과 같은 퍼머 링크를 만들 수 있었지만 링크의 '/ categories /'부분을 제거하고 싶습니다. 내가 현재 사용하고있는 코드는이 코드의 많은, 많은 변화를 시도했지만 내가 얻을 때마다 나는 퍼머을 찾고 있는데요 구조가 내가 이것을 생각하기 시작 오전 404

을 제공

add_action('init', 'video_post_type'); 

function video_post_type() { 
    register_post_type('video', array(
     'labels' => array(
      'name' => 'Videos', 
      'singular_name' => 'Video', 
     ), 
     'rewrite' => array('slug' => 'categories/%category%'), 
     'taxonomies' => array('post_tag', 'category'), 
     'description' => 'Video resources.', 
     'public' => true, 
     'menu_position' => 20, 
     'supports' => array('title', 'editor', 'custom-fields') 
    )); 
    } 

function videos_post_link($post_link, $id = 0){ 
    $post = get_post($id); 
    if (is_object($post)){ 
     $terms = wp_get_object_terms($post->ID, 'category'); 
     if($terms){ 
      return str_replace('%category%' , $terms[0]->slug , $post_link); 
     } 
    } 
    return $post_link; 
} 
add_filter('post_type_link', 'videos_post_link', 1, 3); 

입니다 이 기사와 관련 게시물을 많이 읽었 기 때문에 가능하지 않을 수도 있습니다.

미리 감사드립니다.

답변

1

섹션 'rewrite' => array('slug' => 'categories/%category%')'rewrite' => array('slug' => '%category%')으로 대체하면 %category%으로두면 효과가 있습니다.

중요 사항 : 결국 permalink 옵션으로 이동하여 재설정하십시오.

일부 더 많은 정보는 여기에 회신 mattkrupnik에 대한 Show only specific categories in permalinks for custom post type in WordPress

+0

감사를 찾을 수 있습니다. 불행히도 내가 일하고 있었고 더 이상 코드에 액세스 할 수 없지만이 문제가 다시 발생하면 솔루션을 확실히 시도 할 예정이므로 솔루션을 확인할 수 없습니다. –

관련 문제