1

I have nhl news website and I have taxonomy for each season (ex 2014-15)

Taxonomy in functions:

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

I assign all posts from 'news' category into different terms for each season ex:20132014 20142015

I create taxonomy term query so when I go to this url localhost/nhl/news/?season=20132014 shows me posts from this specific season instead of going here localhost/nfl/season/20132014

What I am trying to do?

To get posts from this term for ex 20142015 (current real season) and show them in the category news localhost/nhl/news without show all posts from all terms and without using url query ?season=(term)

localhost/nhl<--folder name in wamp/news<--categoryname/

Thank you

23
  • remove the 'operator' => 'IN' and try
    – Karun
    Jul 6, 2015 at 8:54
  • @Karun didn't work still I see all posts from all seasons. Did you understand what exactly the problem is?
    – LinekereDe
    Jul 6, 2015 at 9:01
  • Your terminology is really confusing. You say you have a taxonomy per season, then season cannot be the taxonomy in your tax_query. Also, I cannot see why you are using pre_get_posts here. This is stuffing everything around. You can simply remove that. How are your season and other taxonomies joined. As far as I can see you are only querying the season taxonomy. Please properly explain what you want. I say again, your terminology makes no sense at all, it is really confusing and hard to understand Jul 6, 2015 at 9:17
  • Please go and read this post then come back and rephrase your question. You still just show the season taxonomy but nothing about the other taxonomies. Are these even taxonomies? Jul 6, 2015 at 9:31
  • @PieterGoosen I think the use of pre_get_posts is what it is needed to do what the OP wants to do. Please, @LinekereDe don't remove that piece of code so we can see what you have tried so far, but edit the question to provide more accurate inforamtion.
    – cybmeta
    Jul 6, 2015 at 9:32

1 Answer 1

-1

this code will display the post from all taxonomy in wordpress:

$args = array(
    'type'                     => 'post',
    'child_of'                 => 0,
    'parent'                   => '',
    'orderby'                  => 'name',
    'order'                    => 'ASC',
    'hide_empty'               => 1,
    'hierarchical'             => 1,
    'exclude'                  => '',
    'include'                  => '',
    'number'                   => '',
    'taxonomy'                 => 'season',
    'pad_counts'               => false 

    ); 
$taxonomy = get_categories( $args );
foreach ( $taxonomy as $tax ) {

$posts_array = get_posts(
    array(
        'posts_per_page' => -1,
        'post_type' => 'post',
        'tax_query' => array(
            array(
                'taxonomy' => 'season',
                'field' => 'term_id',
                'terms' => $tax->term_id,
            )
        )
    )
);

 print_r( $posts_array ); 
}

if you want to display specific post then pass below codes:

$posts_array = get_posts(
    array(
        'posts_per_page' => -1,
        'post_type' => 'post',
        'tax_query' => array(
            array(
                'taxonomy' => 'season',
                'field' => 'term_id',
                'terms' => 2, // taxonomy id
            )
        )
    )
);

 print_r( $posts_array );
1
  • 2
    You are mixing up terms, categories and taxonomies into one disaster. The blind is leading the blind here, sorry if I offended you, but this is what is happening at the moment Jul 6, 2015 at 10:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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