0

I'm trying to find solution for the following hours now and i don't know if this is applicable.

I have 1 Custom Taxonomy "Years" for Post Type "Post (default)". The taxonomy has 2 Terms: "2014" and "2015".

I have select some posts from category "news" to use the 2 different Taxonomy terms.

This shows me all posts for both taxonomy terms :

http://website.com/category/news/

When I want to display posts from category "news" with taxonomy term "2014" I use the following :

http://website.com/category/news/?years=2014

What I'm trying to do is instead of showing all posts from both taxonomy terms in http://website.com/category/news/ to display only "2015" (term) posts without using the slug ?years=2015 and without display "2014" posts

Taxonomy in functions:

function wptp_register_taxonomy() {
    register_taxonomy( 'years', 'post',
        array(
            'labels' => array(
                'name'              => 'Years',
                'singular_name'     => 'Year',
                'search_items'      => 'Search Year',
                'all_items'         => 'All Years',
                'edit_item'         => 'Edit Year',
                'update_item'       => 'Update',
                'add_new_item'      => 'Add New Year',
                'new_item_name'     => 'New Year',
                'menu_name'         => 'Years',
            ),
            'hierarchical' => true,
            'sort' => true,
            'args' => array( 'orderby' => 'term_order' ),
            'rewrite' => array( 'slug' => 'years' ),
            'show_admin_column' => true
        )
    );
}
add_action( 'init', 'wptp_register_taxonomy' );

Tried this in the category.php but didn't worked:

$args = array(
    'post_type'=> 'post',
    'years'    => '2015',
    );              

$the_query = new WP_Query( $args );
if($the_query->have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post()

Thank you

1

It is because you're using a reserved term "year".

https://codex.wordpress.org/Reserved_Terms

  • 1
    Please explain what happens when you are using this term. – fuxia Jul 20 '16 at 20:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.