Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Categories WordPress


I have a music festival website with festivaldays as categories (wendsday, thursday, friday)

Each day have separate page. The Index page shows all days.

My question,

Is there a way to take all the days (wendsday, thursday ect) from 2013 and put them in a new category named 2013.

And then make a archive template that querys the 2013 category?

Answers (4)


Sébastien | French WordpressDesigner answers:

i think like arnav

Manny comments:

ok, I increased the money now :)

Sébastien | French WordpressDesigner comments:

first : make a backup of your db !


add this in functions.php

function slh_posts_by_year( $post_id ) {
$my_posts = get_posts( array('post_type' => 'post', 'numberposts' => -1 ) );
foreach ( $my_posts as $my_post ){
echo get_the_time('Y',$my_post->ID)."<BR>";
$slh_categories = get_the_category($my_post->ID);
$slh_is_day = false;
$slh_cat_array = array();
foreach($slh_categories as $slh_category) {
if ( ($slh_category->cat_name == "wendsday") OR ($slh_category->cat_name == "thursday") ) {//-------------------------> add all days !!!!!!!!!!!!
$slh_is_day = true;
$slh_cat_array[] = $slh_category->term_id;
if( (get_the_time('Y',$my_post->ID) == "2013") AND ($slh_is_day == true) ) {
$category_ids = $slh_cat_array;
array_push($category_ids, 7); //-------------------------> 7 is the ID of the category "2013" !!!!!!!!!!!!
wp_set_object_terms( $my_post->ID, $category_ids, 'category');

add_action( 'init', 'slh_posts_by_year' );

add all days in thos line :
if ( ($slh_category->cat_name == "wendsday") OR ($slh_category->cat_name == "thursday") ) {//-------------------------> add all days !!!!!!!!!!!!

change the id in this line
array_push($category_ids, 7); //-------------------------> 7 is the ID of the category "2013" !!!!!!!!!!!!
of course you must have a category "2013" :)

and go to your backoffice

if you haven't change my code, all posts published in 2013 in the category "wendsday" or "thursday" are now in the category "2013" too.

Sébastien | French WordpressDesigner comments:

It's possible to add programmatically a category for each year.
It's possible to code the function to sort all posts for all years (if a post is published int he category 'thurday' in 2011, it will appear in the category "2011" too)
but your offered amount is too low for this work.

Sébastien | French WordpressDesigner comments:

have you try my code ?
is it ok ?

Sébastien | French WordpressDesigner comments:

I see in your site that you have create a category "2013" and use my code and all seems ok :)
good !

Manny comments:

Hi, I just duplicated the index page code ;)


Arnav Joy answers:

yes it is possible , but your offered amount is too low for this work.


Dbranes answers:

It sounds you're just looking for a custom page to show all posts of the year 2013 that are in the days categories.

For example


Is that correct?


If true, then here's a simple example of a template file for your <em>festival</em> page, without modifying your current category structure:

* Template Name: Festivals per year
$year = intval( get_query_var( 'festyear' ) ); // input
$args = array(
'date_query' => array( array( 'year' => $year ) ),
'posts_per_page' => -1,
'tax_query' => array(
'taxonomy' => 'category',
'field' => 'slug',
'terms' => array( 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', 'sunday' ),
) );
$q = new WP_Query( $args );
if ( $q->have_posts() ):
while ( $q->have_posts() ): $q->the_post();
get_template_part( 'content', 'festival' ); // custom template part
_e( 'Sorry - No posts found !' );

where you add your own <em>content-festival.php</em> file in the active theme's directory.

You can then add the following to your <em>functions.php</em> file:

function festyear_query_vars( $qvars ) {
array_push( $qvars, 'festyear' );
return $qvars;

add_filter( 'query_vars', 'festyear_query_vars' );

so you can access the <em>festival </em>page with the <em>festyear</em> parameter :

where it's possible to rewrite it to look more pretty:

with for example <em>add_rewrite_rules()</em>.


Bob answers:

Please checkout this plugin that might become helpful to you.

[[LINK href=""]][[/LINK]]

If you like how it works then we can modify it's behavior to show categories also.

Bob comments:

Checkout this plugins also

[[LINK href=""]][[/LINK]]

[[LINK href=""]][[/LINK]]

[[LINK href=""]][[/LINK]]

[[LINK href=""]][[/LINK]]

I think instead of creating different archive template I can create shortcode for you.

you need to just specify year and categories in you page.
That page will display all post of that year shorted by categories.
for example
[show_posts year="2013" cat="wendsday, thursday, friday"]

above code will get all the posts of 2013 and display with category title.

output would be like this.
<strong>2013 Archive</strong>

Post 1
Post 2
Post 3

Post 1
Post 2
Post 3