0

I want to display in the page.php all category (now it's do it) but when i click to a specific category, then it's go to the archive.php and dipslay me all category again, but i want display the post from specific category on which i click.

I have page.php file

$paged = (get_query_var('paged')) ? get_query_var('paged') : 0;

 $args = array(
    'suppress_filters' => true,
    'post_type' => 'events',
    'posts_per_page' => 6,
 );

$the_query = new WP_Query( $args );
$total = $the_query->found_posts;

$terms = get_terms( 'event', array(
    'hide_empty' => false
  ) );
  $current_term = get_queried_object()->term_id;

  if ( ! empty( $terms ) && ! is_wp_error( $terms ) ):
?>
<ul class="term-filter">
  <li <?php if ( is_null( $current_term ) ): ?>class="active"<?php endif; ?>>
    <a class="h7 uppercase" href="<?php echo get_post_type_archive_link( 'event' ); ?>"><?php _e( 'ALL'); ?></a>
  </li>
  <?php foreach ( $terms as $term ): ?>
    <li <?php if ( $current_term == $term->term_id ): ?>active<?php endif; ?>">
      <a href="<?php echo get_term_link( $term ); ?>"><?php echo $term->name; ?></a>
    </li>
  <?php endforeach; ?>
</ul>
<?php endif; 

archive.php

$args = array(
   'post_type' => 'events',
   'posts_per_page' => -1,
  );

  $query = new WP_Query( $args );

    if ( $query->have_posts() ): ?>
    <div>
      <?php while ( $query->have_posts() ):$query->the_post(); ?>
        <div class=""><h2><?php the_title(); ?></h2></div>
      <?php endwhile; wp_reset_postdata(); ?>
    </div>

     <?php endif; ?>

Your Answer

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

Browse other questions tagged or ask your own question.