I’m developing a Latin Literature digital library for my thesis.
Right now I’m working on the author’s archive page.
Authors is a Custom Post Type registered as ‘auctores’ with a custom taxonomy assigned to it named ‘periodi’.
In the archive page (archive-auctores.php) I’d like to show all the authors listed by a meta field and other three columns: Periods (which refers to the custom taxonomy that I’d like to make a filter), Number of books (there should be the number of books (cpt) assigned to that author) and Gener (where to display all the literary genres of the books assigned to that author and it would be another taxonomy assigned to the book cpt via the cpt-onomies plugin). The number column should be sortable (asc/desc) while i’d like to make a filter for periods and for kinds.
I.E. –> opening the archive page it will show up the complete list of authors. So it should be possible to filter the authors for period and the page should show just the authors “tagged” with that specific taxonomy term.
I thought I had found a solution here, but when I try to select one term in the drop down the list remain the same.
I’m surely missing something.
That’s the code of my template right now:
<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>
Any help would be really appreciated.
Thanks!
IF you want the list of authors to be limited based on the drop-down selection, then you’ll need to modify the query and utilize the Taxonomy Query Parameters:
Modify the code so that it responds to the form post as follows: