i have displayed all my categories on a page through loop and whenever i click on any category its id is passed and posts related to that category are displayed .but its also shows the id of that category in the url . what i want is to do something in which url shows the name of the particular category that i have clicked . for this i have tried passing name of the category in the link then the id it solves the problem of the url i.e: category name shows up in the url but it creates another problem that it does not open the posts of that category but show error page not found : my code for displaying all categories is this:
<?php
foreach ( $categories as $cat ) {
$id = $cat->term_id;
//$name = $cat->cat_name;
echo '<a href="'.get_site_url() . '/state_league_archives?id='.$id.'">'.$cat->cat_name.'</a>';
?>
<hr>
<?php
}
?>
and this id i get on the archive page to show its posts like this:
<?php
$cat_id= $_GET['id'];
$args = array('showposts'=>25, 'category' => '$cat_id' ,'post_type'=>'stateleague-pos-type','category__in'=>array($cat_id));
$query = new WP_Query($args);
while ( $query->have_posts() ) : $query->the_post(); ?>
<h1><a href="<?php echo the_permalink();?>"><?php the_title();?></a></h1>
<?php the_content(); ?> |
<a href="<?php the_permalink(); ?>">
Read more
</a>
<div class="row">
<div class="ct-divider"> </div>
</div>
<?php endwhile; ?>