2017-02-16 5 views
1

저는 Manufactures라는 사용자 정의 게시 유형을 만들고 많은 게시물과 카테고리를 추가했습니다. 단일 게시물 페이지는 작동하지만 카테고리/아카이브 페이지에는 게시물이 표시되지 않습니다.WordPress 사용자 정의 게시물 유형 범주 페이지가 게시물을로드하지 않습니다.

제조사가 다른 카테고리로 분류되어 각 카테고리의 모든 게시물의 아카이브를 표시해야합니다. 제조업체> 카테고리> Ge Speedtronic으로 이동하여 "카테고리보기"를 클릭하면 아래 나열된 URL로 이동합니다. 이 혼란을 얻는 곳

http://localhost/category/manufactures/ge-speedtronic/

이입니다. 사용자 지정 게시 유형 "제조 업체"에 대해 사용하고있는 범주도 내 다른 사용자 지정 게시 유형 및 기본 게시 섹션 아래에 표시됩니다. 그래서 하위 카테고리가있는 Manufactures-Cat 카테고리를 만들었습니다. 이로 인해 문제가 발생할 수 있습니다.

카테고리 페이지에 어떤 게시물이로드되지 않았는지 알 수 있습니까? 특정 게시물 유형에서만 나타나는 카테고리를 만들 수 있습니까?

이 코드는이 내 category.php 파일의 코드 내 functions.php

add_action('init', 'create_manufacturers'); 
function create_manufacturers() { 
    register_post_type('manufacturers', 
    array(
     'labels' => array(
     'name' => __('Manufacturers'), 
     'singular_name' => __('Manufacturer') 
    ), 
     'hierarchical'  => true, 
     'public'    => true, 
     'show_ui'    => true, 
     'show_in_menu'  => true, 
     'show_in_nav_menus' => true, 
     'show_in_admin_bar' => true, 
     'menu_position'  => 5, 
     'can_export'   => true, 
     'has_archive'   => true, 
     'has_category'   => true, 
     'exclude_from_search' => false, 
     'publicly_queryable' => true, 
     'capability_type'  => 'post', 
     'taxonomies' => array('category'), 
     'rewrite' => array('slug' => 'manufacturers'), 
     'supports' => array('title', 'editor', 'author', 'thumbnail', 'excerpt', 'comments') 
    ) 
); 
} 

입니다.

<?php get_header();?> 
<div class="container page-category-wrap"> 
    <div class="row"> 
     <div class="col-md-9"> 
      <?php if (have_posts()) : while (have_posts()) : the_post(); ?> 
      <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>> 
       <div class="entry-content"> 
        <h3><?php the_title(); ?></h3> 
        <?php the_content(); ?> 
       </div> 
      </article> 
      <?php endwhile; endif; ?> 
     </div> 
     <div class="col-md-3"> 
      <?php dynamic_sidebar ('sidebar-1');?> 
     </div> 
    </div> 
</div> 
<?php get_footer(); ?> 

답변

1

당신은 쿼리 객체에 사용자 정의 포스트 유형을 추가 할 수 있습니다 도움을

function my_query_post_type($query) { 
    if (is_category() && (! isset($query->query_vars['suppress_filters']) || false == $query->query_vars['suppress_filters'])) { 
     $query->set('post_type', array('post', 'manufacturers')); 
     return $query; 
    } 
} 
add_filter('pre_get_posts', 'my_query_post_type'); 

https://codex.wordpress.org/Plugin_API/Action_Reference/pre_get_posts

+0

감사합니다! 그게 효과가 있었고 지금은 페이지에 게시물을 볼 수 있습니다. 디버그 모드에서 나는이 메시지 ... 정의되지 않은 인덱스 받고 있어요 : 내가 업데이트 한 라인 177의 경우에 suppress_filters (is_category() && 거짓 ==의 $ 질의 -> query_vars [ 'suppress_filters']) { –

+0

을 내 대답. 이렇게하면 경고 메시지가 표시되지 않습니다. –

+0

감사합니다. –

관련 문제