Wordpress wp_获取自定义帖子类型的文档不工作?

Wordpress wp_获取自定义帖子类型的文档不工作?,wordpress,Wordpress,我正在使用wp_get_归档来检索在我的自定义帖子类型“下载”中发布的帖子的每月日期列表 但它不起作用,我做错了什么 我正在使用workpress 3.3 谢谢 代码 <?php $args = array( 'post_type' => 'download', 'type' => 'monthly', 'show_count' => '1' ); ?> <?php wp_get_a

我正在使用wp_get_归档来检索在我的自定义帖子类型“下载”中发布的帖子的每月日期列表

但它不起作用,我做错了什么

我正在使用workpress 3.3

谢谢

代码

<?php   $args       = array(

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

); ?>

<?php wp_get_archives( $args ); ?>
// 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 );

}
wp_get_归档文件();不支持将“post_type”作为参数

有一个讨论[这里][1]:关于支持它的黑客行为。本文提供了一些链接,这些链接指向另一个使用过滤器的解决方案,该过滤器应用于sql查询,用于选择要包含在归档结果中的帖子。看看如何在general-template.php中应用过滤器,它也应该可以工作。

wp_get_archives();不支持将“post_type”作为参数

有一个讨论[这里][1]:关于支持它的黑客行为。本文提供了一些链接,这些链接指向另一个使用过滤器的解决方案,该过滤器应用于sql查询,用于选择要包含在归档结果中的帖子。看看如何在general-template.php中应用过滤器,它也应该可以工作。

一些提示:

提示1使用自定义post类型存档插件(任何更改后更新永久链接)

提示2WPML插件+自定义帖子类型存档:

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);
一些提示:

提示1使用自定义post类型存档插件(任何更改后更新永久链接)

提示2WPML插件+自定义帖子类型存档:

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);

嗯,你自己试过吗?我在本文中尝试了很多查询和查询,但运气不太好。嗯,你自己也尝试过吗?我在本文中尝试了很多查询和查询,但运气不太好。