Forum Replies Created
-
AuthorPosts
-
rgval
MemberI am so sorry, guys, it was a mistake in my taxonomy name.
I used 'year' as the taxonomy term, and is reserved for WP.I am still surprised about how difficult is to list posts grouped by a custom taxonomy in an archive.
I thought it could be easier with Genesis (perhaps I'm doing something wrong and there is an easier way...)Anyway, the working code is here:
<?php /** * STUDENT ARCHIVE */ // Replace the genesis loop remove_action( 'genesis_loop', 'genesis_do_loop' ); add_action( 'genesis_loop', 'my_custom_loop' ); function my_custom_loop() { //start by fetching all terms for the year taxonomy $terms = get_terms( 'graduation-year', array( 'orderby' => 'name', 'order' => 'DESC' ) ); // now run a query of students for each year foreach( $terms as $term ) { // Define the query $args = array( 'post_type' => 'student', 'graduation-year' => $term->slug ); $query = new WP_Query( $args ); // output the term name in a heading tag echo'<h2>' . $term->name . '</h2>'; // output the post titles in a list echo '<ul>'; // Start the Loop while ( $query->have_posts() ) : $query->the_post(); ?> <li class="student-list" id="post-<?php the_ID(); ?>"> <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a> </li> <?php endwhile; echo '</ul>'; // use reset postdata to restore orginal query wp_reset_postdata(); } } genesis(); ?>
rgval
MemberThanks braddalton. What I am trying to do is a template for the custom post archive, so I can list all posts in one page.
I am surprised is it not more easy to list posts by years...(not the publication year, but a custom numeric field). Apart from my problems with the loop, I though this should a be quite common way of sorting content. I am doing something wrong? perhaps another more efficient structure in the posts, etc.
rgval
Member😀 Yes, good point. I do have post with every taxonomy.
I confirmed they work with the taxonomy permalink -
AuthorPosts