Filter posts in a category by tag and by year
-
Hi,
Im building a site with a student gallery that has a category with over 400 post’s of past work (Images, Title Content). On the landing page of the gallery, I have chosen to show 40 random items with a mini navigation bar.
What I want to do give the navigation bar the ability allow me to filter the posts by the year associated with them and also by their associated tags. Like this:
View by Tags View by Years
List all tags List all yearsshow items here
If i was to click on ‘2009’, I want all the items posted in 2009 to come up, regardless of how many there are.
I have tried adding this piece of code to to the functions.php file :
add_filter( ‘getarchives_where’, ‘customarchives_where’ );
add_filter( ‘getarchives_join’, ‘customarchives_join’ );function customarchives_join( $x ) {
global $wpdb;
return $x . ” INNER JOIN $wpdb->term_relationships ON ($wpdb->posts.ID = $wpdb->term_relationships.object_id) INNER JOIN $wpdb->term_taxonomy ON ($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id)”;
}function customarchives_where( $x ) {
global $wpdb;
$studentGallery = get_category_by_slug(‘studentportfolio’);
$id = $studentGallery->term_id;
$include = $id; // category id to include
return $x . ” AND $wpdb->term_taxonomy.taxonomy = ‘category’ AND $wpdb->term_taxonomy.term_id IN ($include)”;
}<?php wp_get_archives( ‘type=yearly&format=html&show_post_count=-1’ ); ?>
It seems to display the available years of the category but when i click on the years it takes me to another page and lists all of the posts in 2013 of the whole site. Can anybody help 🙂
- The topic ‘Filter posts in a category by tag and by year’ is closed to new replies.