【发布时间】:2014-10-30 15:27:47
【问题描述】:
这很好用。我在下拉列表中看到自定义帖子类型存档,但是当我选择任何月份时,我会在该存档页面上看到所有自定义帖子。虽然每个月只有一个帖子,例如我在 7 月有 1 个帖子,在 8 月有 1 个帖子,下拉计数器显示正确,但是当我选择它们时,我会看到所有自定义帖子,而不仅仅是一个。有什么解决办法吗?
add_filter( 'getarchives_where', 'custom_getarchives_where' );
function custom_getarchives_where( $where ){
$where = str_replace( "post_type = 'post'", "post_type IN ( 'post', 'fruits' )", $where );
return $where;
}
add_action( 'pre_get_posts', 'add_podcasts_to_archive' );
function add_podcasts_to_archive( $query ) {
if ( $query->is_main_query() && $query->is_archive() && !is_admin() )
$query->set( 'post_type', array( 'post', 'fruits' ) );
return $query;
}
【问题讨论】:
-
我怀疑您的问题是存档页面本身的代码,您是否在存档页面上运行自定义查询
标签: wordpress archive custom-post-type