2014-06-09 2 views
1

내 wordpress 인스턴스에 부울 true/false 값인 5 개의 사용자 정의 필드가 있습니다. 그래서 하이픈 URL에 값을 추가하는 경우와 -Permalink from custom post type wordpress

property_type_investment, property_type_office, property_type_rental, property_type_industrial, property_type_land

는 해당하는 메타 값의 각을 확인합니다이 사용자 정의 포스트 유형에 대한 영구 링크를 생성 할 수 있나요 ?

예 : property_type_investment, property_type_office 및 property_type_land가 true 인 경우. 나는

가 여기 내 레지스터 포스트 타입/

/명부/투자 사무실 토지/포스트 제목 ... 영구 링크가되고 싶습니다.

register_post_type('properties', 
    array(
     'labels' => array(
      'name' => 'Properties', 
      'singular_name' => 'Property', 
      'add_new' => 'Add New', 
      'add_new_item' => 'Add New Property', 
      'edit' => 'Edit', 
      'edit_item' => 'Edit Property', 
      'new_item' => 'New Property', 
      'view' => 'View', 
      'view_item' => 'View Property', 
      'search_items' => 'Search Properties', 
      'not_found' => 'No Property found', 
      'not_found_in_trash' => 'No Properties found in Trash', 
      'parent' => 'Parent Property' 
     ), 

     'public' => true, 
     'rewrite' => array('slug'=>'listings'), 
     'menu_position' => 15, 
     'supports' => array('title', 'editor', 'comments', 'thumbnail', 'custom-fields'), 
     'taxonomies' => array(''), 
     'has_archive' => true 
    ) 
); 

답변

2

규칙을 다시 작성할 수 있습니다.

function prefix_investment_rewrite_rule() { 
    add_rewrite_rule('listings/([^/]+)/investment-office-land', 'index.php?listings=$matches[1]&investment-office-land=yes', 'top'); 
} 

add_action('init', 'prefix_investment_rewrite_rule'); 

//You should register the query var 
function prefix_register_query_var($vars) { 
    $vars[] = 'investment-office-land'; 
    return $vars; 
} 

add_filter('query_vars', 'prefix_register_query_var'); 

// assign a template 
function prefix_url_rewrite_templates() { 
    if (get_query_var('investment-office-land') && is_singular('listings')) { 
     add_filter('template_include', function() { 
      return get_template_directory() . '/single-listings-investment-office-land.php'; 
     }); 
    } 
} 

add_action('template_redirect', 'prefix_url_rewrite_templates'); 

register_post_type 이후에 다시 쓰기 규칙을 반드시 삭제하십시오.

flush_rewrite_rules(); 
+0

응답 해 주셔서 감사합니다 ...이 솔루션은 투자 오피스 - 랜드 조합에만 사용할 수있는 것 같습니다. 내가 나열한 5 개 필드를 기반으로 가능한 모든 조합을 해결할 수 있어야합니다. 예 :/투자 /,/사무실 임대 /,/투자 사무실 임대/토지 산업/등 ... – Greg

+1

이것을 확인할 수 있습니까 [link] (http://code.tutsplus.com/ articles/custom-page-template-page-based-url-rewrite-wp-30564)를 사용하십시오. 이것은 내가 위에서 쓴 모든 것을 깊이 설명했다. – Arka

0

당신은 당신의 관리자 패널 -> 설정 -> permalink-> 사용자 정의 구조 /%category%/%postname%/으로 사용하여 간단한 방법으로 사용하여 테스트 할 수 있습니다.