• I’ve created a date.php template, where the visitor browse the archive of the custom posts grouped by year. I would like to create a slightly helpful structure, giving the possibility to browse the archive by category.

    Is there a way to retrieve the list of terms of a custom taxonomy for the custom posts in a certain archive? For example if you choose “2016” and you arrive at the archive page of the custom posts written in 2016, is there a way to retrieve the list of the categories of all the posts of that year?

    I’ve searched if existed a plugin that would expand the arguments for wp_list_category, giving the possibility to refer to the date, but I’ve not found nothing.

    If it was found that for that year the categories would be “Cat A” and “Cat B”, if you would click on the link, you would go to the url “www.sitename.com/custom-taxonomy-cat-a” or to “www.sitename.com/2016/cat-a”?

    The page I need help with: [log in to see the link]

Viewing 16 replies (of 16 total)
  • Thread Starter fibbo8

    (@fibbo8)

    Ok! This works.
    I can’t make a comparison now, but I think I was mistaking somenthing when passing the arguments to the function.

    Another couple of questions ??
    I’ve a second custom taxonomy and I’d like to do the same “filter” that I’ve done referencing the query string for year.
    So I’ve set another query var and I’ve modified the code above in something like.
    The code works. I can able to filter the posts that share the year and the brand, or the price and the brand.

    $archive_year = get_query_var('anno-rif');
     $archive_price = get_query_var('prezzo');
     $terms = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) );
     if (empty ($archive_year) && empty ($archive_price)) {
     $posts_in = get_posts() 
     } // arguments for the general loops on taxonomy term
     if (isset($archive_year)) { 
     $posts_in = get_posts() 
     } //arguments for filter according year
     if (isset($archive_price)) {
     $posts_in = get_posts() 
     } //arguments for filter according price

    But I can’t well imagine if this setup will simply mess the code or if it also will cause problems.

    At the beginning of this prolific discussion you have spoke about security concerns when using the query string.
    In functions.php I’ve simply write:

    function query_var_anno( $vars ){
      $vars[] = 'anno-rif';
      return $vars;
    }
    add_filter( 'query_vars', 'query_var_anno' );

    Inside the templates this function is invoked as above.

    Does where does come the issues?

Viewing 16 replies (of 16 total)
  • The topic ‘Retrieve list of categories inside date.php template’ is closed to new replies.