2016-10-07 2 views
3

한 가지 문제가 있습니다. 몇 시간 전에 웹 검색을 해결하려고했지만 지금은 해결할 수 없습니다. 어떤 아이디어 나 단서도 환영합니다 ...WordPress 마이그레이션 후 category-slug.php가 작동하지 않습니다.

(더 이상의 개발 활동이없는) 플러그인 (CCTM)을 사용하는 WordPress 사이트를 마이 그 레이션하여 사용자 정의 게시물 유형과 "recetas"를 사용하는 필드를 등록하려고합니다. 네이티브 WordPress 카테고리 "recetas"를 자신의 게시물에 포함 시켰습니다.

새 빌드에서는 functions.php에 사용자 지정 게시 유형을 수동으로 등록하고 WordPress의 기본 XML 가져 오기 도구를 통해 콘텐츠를 가져옵니다.

add_action('init', 'codex_book_init'); 
function codex_book_init() { 
    $labels = array(
     'name'    => _x('Recetas'), 
     'singular_name'  => _x('Receta'), 
     'menu_name'   => _x('Recetas'), 
     'name_admin_bar'  => _x('Recetas'), 
     'add_new'   => _x('Agregar Nueva'), 
     'add_new_item'  => __('Agregar Nueva Receta'), 
     'new_item'   => __('Nueva Receta'), 
     'edit_item'   => __('Editar Receta'), 
     'view_item'   => __('Ver Receta'), 
     'all_items'   => __('Todas las Recetas'), 
     'search_items'  => __('Buscar Receta'), 
     'parent_item_colon' => __('Receta Padre:'), 
     'not_found'   => __('Sin Recetas encontradas.'), 
     'not_found_in_trash' => __('Sin Recetas encontradas en papelera.') 
    ); 
    $args = array(
     'labels'    => $labels, 
     'description'  => __('Recetas'), 
     'public'    => true, 
     'publicly_queryable' => true, 
     'show_ui'   => true, 
     'show_in_menu'  => true, 
     'query_var'   => true, 
     'rewrite'   => array('slug' => 'recetas'), 
     'capability_type' => 'post', 
     'has_archive'  => true, 
     'hierarchical'  => true, 
     'menu_position'  => 5, 
     'menu_icon'   => 'dashicons-admin-post', 
     'taxonomies'   => array('category'), 
     'supports'   => array('title', 'thumbnail', 'excerpt', 'editor', 'comments') 
    ); 
    register_post_type('recetas', $args); 
} 

모든 콘텐츠는 사용자 정의 포스트 유형에서 하나의 기사에 확인을 가져오고 새로운 루프 WP_Query(array('posts_type'=> 'recetas')의 내용이 너무 좋아집니다. 그러나 문제는 카테고리 기본 템플릿 (category-recetas.php)에서 기본 워드 프레스 루프 <?php if (have_posts()) : while (have_posts()) : the_post(); ?>으로 게시물 유형 기사를 가져 오는 데 사용됩니다. 그것은 간단하게 작동하지 않으며, 어떤 게시물도 카테고리 "recetas"에서 유래하지 않습니다.

내가 영구 링크를 다시 저장하려고 archive-slug.php을 시도, category-id.php을 시도, 맞춤 분류 "recetas"를 등록하려고

,하지만 아무것도 작동 ...

+0

여기 가시성에 따라, [워드 프레스 StackExchange] (http://wordpress.stackexchange.com/) 사이트에서 더 나은 성공을 할 수도 있습니다. –

+0

퍼머 링크를 다시 저장하십시오. – Jrod

+0

시도했지만 아무 일도 일어나지 않습니다. – Tuux

답변

0

는 wordpress.stackexchange에서 @Max Yudin에 감사를 해결 - 그의 대답은 고정 문제. @Max

카테고리에서 LINK

대답은 내장 분류 게시물 만이 아니라 사용자 정의 포스트 유형이다. 따라서 pre_get_posts 훅을 호출해야합니다.

이 훅은 쿼리 변수 개체가 생성 된 후에 실제로 쿼리가 실행되기 전에 호출됩니다. 다음 코드를 functions.php 또는 맞춤 플러그인에 추가하십시오. 비록 테스트를 거치지 않았다.

<?php 
add_filter('pre_get_posts', 'query_post_type'); 
function query_post_type($query) { 
    if(is_category()) { 
     $post_type = get_query_var('post_type'); 
     if(!$post_type) { 
      $post_type = array('nav_menu_item', 'post', 'recetas'); // don't forget nav_menu_item to allow menus to work! 
     } 
     $query->set('post_type', $post_type); 
     return $query; 
     } 
} 
관련 문제