Support » Fixing WordPress » Displaying *only* posts in current category?

  • Resolved smallmultiple

    (@smallmultiple)


    I created a custom post type called “Events” and a custom taxonomy to categorize each event:

    function event_custom_post_type()
    {
      register_post_type('events',
                          array(
                              'labels'      => array(
                                  'name'          => __('Events'),
                                  'singular_name' => __('Event'),
                              ),
                              'public'      => true,
                              'has_archive' => true,
                          )
      );
      register_taxonomy( 'event_categories', 
        array( 'events' ), 
        array(
            'label' => 'Events',
            'hierarchical' => true,
          ));
    }

    In my custom taxonomy page, I want to be able to filter events by category. Except currently, my query is grabbing *all* posts in all categories, rather than just the current category:

    <?php
            if ( get_query_var('paged') ) $paged = get_query_var('paged');  
            if ( get_query_var('page') ) $paged = get_query_var('page');
            $query = new WP_Query( array( 'post_type' => 'events', 'paged' => $paged ) );
            if ( $query->have_posts() ) : ?>
              <?php while ( $query->have_posts() ) : $query->the_post(); ?>	
                <!-- display events in current category -->
              <?php endwhile; wp_reset_postdata(); ?>
            <?php else : ?>
              <p>There are no upcoming events</p>
            <?php endif; ?>

    Where in this query would I specify *only* the current category?

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • You must be logged in to reply to this topic.