【发布时间】:2016-04-01 16:35:39
【问题描述】:
我正在为我的论文开发一个拉丁文学数字图书馆。 现在我正在作者的存档页面上工作。 作者是注册为“auctores”的自定义帖子类型,并为其分配了一个名为“periodi”的自定义分类。 在存档页面(archive-auctores.php)中,我想显示由元字段和其他三列列出的所有作者:时期(指的是我想制作过滤器的自定义分类法),数字of books(应该有分配给该作者的图书数量(cpt))和 Gener(在哪里显示分配给该作者的图书的所有文学体裁,这将是通过 cpt-分配给图书 cpt 的另一种分类法-词组插件)。数字列应该是可排序的(asc/desc),而我想为句点和种类制作一个过滤器。 IE。 --> 打开存档页面,它将显示完整的作者列表。因此,应该可以过滤作者的时期,并且页面应该只显示使用该特定分类术语“标记”的作者。
我以为我找到了解决方案 here,但是当我尝试在下拉列表中选择一个术语时,列表保持不变。
我肯定错过了什么。 这就是我现在模板的代码:
<form method="post" action="<?php the_permalink()?>">
<select name="periodi" id="selectperiodo" class="postform" onchange="submit();">
<option value="">Tutti i periodi</option>
<?php
$args = array(
'orderby' => 'ID',
'order' => 'ASC',
'hide_empty' => false,
'fields' => 'all',
'hierarchical' => true,
'pad_counts' => false,
'get' => '',
'child_of' => 0,
'parent' => '',
'childless' => false,
'cache_domain' => 'core',
'update_term_meta_cache' => true,
'meta_query' => '',
'parent' => 0
);
$terms = get_terms('periodi', $args);
if ( $terms ) {
foreach ( $terms as $term ) {?>
<option <?php if($term->slug == $_POST['periodi']){ echo 'selected="selected"';} ?> value="<?php echo esc_attr( $term->slug )?>"><?php echo esc_html( $term->name ) ?></option>
<?php }
}
?>
</select>
</form>
<table class="dataTable table table-hover">
<tr>
<th>Nome</th>
<th>Periodo</th>
<th>Opere</th>
<th>Genere</th>
</tr>
<?php $auctores_query = new WP_Query(array(
'post_type' => 'auctores',
'posts_per_page' => -1,
'order' => 'ASC',
'meta_key' => 'nome_classico',
'orderby' => 'meta_value',
)
); ?>
<?php $j = 0 ?>
<?php while ($auctores_query->have_posts()) : $auctores_query->the_post(); ?>
<?php $additional_class = (++$j % 2 == 0) ? 'even' : 'odd'; ?>
<tr class="<?php echo $additional_class ?>">
<td><?php the_title( '<h3 class="entry-title"><a href="' . esc_url( get_permalink() ) . '" title="' . esc_attr( sprintf( __( 'Collegamento alla pagina di %s', 'antiquarialatina' ), the_title_attribute( 'echo=0' ) ) ) . '" rel="bookmark">', '</a></h3>' )?></td>
<td>
<?php
$terms = get_the_terms( $post->ID, 'periodi' );
if ( $terms && ! is_wp_error( $terms ) ) :
$periodi_links = array();
foreach ( $terms as $term ) {
$periodi_links[] = $term->name;
}
$on_draught = join( ", ", $periodi_links );
?>
<?php echo $on_draught; ?>
<?php endif; ?>
</td>
<td><span class="badge"><?php
$args = array('post_type' => 'texti',
'tax_query' => array (
array ( 'taxonomy' => 'auctores',
'field' => 'id',
'terms' => get_the_ID()
)
));
$query = new WP_Query( $args );
// the query
echo $query->found_posts;
?></span></td>
</tr>
<?php endwhile; ?>
</table>
任何帮助将不胜感激。 谢谢!
【问题讨论】:
-
您的
$auctores_query不会尝试根据您描述的元字段进行过滤。需要对其进行更改以合并基于这些下拉字段的过滤。 -
感谢您的回答。请让我理解。 $auctores_query 现在显示所有按我想要的 meta_key 'nome_classico' 排序的作者。我要做的是在从下拉列表中选择分类法“periodi”的特定术语时仅显示其作者。我的主要问题是第二列。我不知道如何将过滤合并到查询中。对不起我的英语不好!
标签: php wordpress custom-post-type archive custom-taxonomy