2012-01-20 3 views
1

wp_get_archives를 사용하여 내 맞춤 게시 유형 '다운로드'에 게시물이 게시 된 날짜의 월간 목록을 검색하고 있습니다.맞춤 게시 유형에 대한 wp_get_archives가 작동하지 않습니까?

하지만 작동하지 않습니다. 내가 뭘 잘못하고있는 걸까요?

나는 workpress 3.3

감사

CODE

<?php $args  = array(

    'post_type'  => 'download', 
    'type'   => 'monthly', 
    'show_count' => '1' 

); ?> 

<?php wp_get_archives($args); ?> 


이것은 내가 참고로 내 사용자 지정 POST 유형 등록 방법 IS를 사용하고

// Downloads Post Type 
add_action('init', 'create_post_type'); 
function create_post_type() { 
    $args = array(
     'labels' => post_type_labels('Download'), 
     'public' => true, 
     'publicly_queryable' => true, 
     'show_ui' => true, 
     'show_in_menu' => true, 
     'query_var' => true, 
     'rewrite' => true, 
     'has_archive' => true, 
     'capability_type' => 'post', 
     'hierarchical' => false, 
     'menu_position' => null, 
     'taxonomies' => array('group'), 
     'supports' => array('title', 
      'editor', 
      'author', 
      'thumbnail', 
      'excerpt', 
      'comments' 
     ) 
    ); 

    register_post_type('download', $args); 

} 

답변

1

wp_get_archives(); 'post_type'을 인수로 지원하지 않습니다.

해킹에 대한 토론이 여기 [0] : http://wordpress.org/support/topic/archive-list-and-page-for-custom-post-types-mysql?replies=9 있습니다. 기사에는 아카이브 결과에 포함 할 게시물을 선택하기위한 SQL 쿼리에 적용되는 필터를 사용하는 다른 솔루션에 대한 링크가 몇 가지 있습니다. 필터가 general-template.php에 어떻게 적용되는지 살펴보면 필터가 작동해야합니다.

+1

흠, 직접 해 보셨습니까? 나는이 기사에서 많은 querys와 쿼리를 시도했지만 많은 행운이 없다. – Joshc

0

몇 가지 힌트 :

힌트 1를 사용하여 사용자 정의 포스트 형 - 아카이브 플러그인 (변경 후 업데이트 퍼머 링크)

힌트 2 WPML 플러그인 + 사용자 정의 포스트 형-아카이브 :

function CPT1_join($join) { 
    global $wpdb; 
    $join = " JOIN pav_icl_translations t ON t.element_id = pav_posts.ID AND t.element_type='CUSTOM_POST_TYPE1' "; 
    return $join ; 
} 

function CPT2_join($join) { 
    global $wpdb; 
    return $join = " JOIN pav_icl_translations t ON t.element_id = pav_posts.ID AND t.element_type='CUSTOM_POST_TYPE2' "; 
} 

function wp_get_archives_filter($where, $options) { 
    global $wpdb; // get the DB engine 

    if(!isset($options['post_type'])) return $where; // OK - this is regular wp_get_archives call - don't do anything 

    $post_type = $wpdb->escape($options['post_type']); // escape the passed value to be SQL safe 

    if($post_type == 'all') 
      $post_type = ''; // if we want to have archives for all post types 
    else $post_type = "post_type = '$post_type' AND"; // otherwise just for specific one 

    if($options['post_type'] == 'CUSTOM_POST_TYPE1'){ 
     add_filter('getarchives_join', 'CPT1_join');  
     }elseif($options['post_type'] == 'CUSTOM_POST_TYPE2'){ 
     add_filter('getarchives_join', 'CPT2_join'); 
     } 

    $where = str_replace('post_type = \'post\' AND', $post_type, $where); 
    return $where; 
} 
add_filter('getarchives_where', 'wp_get_archives_filter', 10, 2); 
관련 문제