• Hello,

    I’m trying to generate a page where all of my categories are displayed with links to their respective category-pages but with one catch: I want to be able to pass a parameter in the categories’ URL so that I can combine 2 categories together.

    To make myself clear: I have a taxonomy named Cars and a taxonomy named Countries, when someone clicks to any one of the Countries he goes to https://mysite.com/?country=country_name.

    In that specific page a list of all the “Cars” terms are displayed as links. Of course that can be done with wp_list_categories() but using that I can’t pass the second attribute (the “country_name”). So the URL of each “Car” taxonomy link should be https://mysite.com/?country=country_name&car=hyundai.

    Now if there was a way to do something like this:

    In dummy code:

    <?php $country_name = $_GET['country_name']; ?>
    
    <?php loop_through_all_car_taxonomy(); ?>
    
    <li>
    <a href="<?php bloginfo('url'); ?>/country=<?php echo $country_name; ?>&car=<?php echo $cat->slug; ?>"> <?php echo $cat->cat_name; ?></a>
    </li>
    
    <?php end_loop(); ?>

    Any ideas?

Viewing 1 replies (of 1 total)
  • Thread Starter Vassilis Mastorostergios

    (@silencerius)

    I figured it out, it’s pretty simple and you use the get_categories() function

    <?php $categories = get_categories( array('taxonomy' => 'country') ); ?>
    
    						<?php foreach ( $categories as $category ) : ?>
    
    							<li><?php bloginfo('url'); ?>/?nomoi=<?php echo $tax_nomos; ?>&country=<?php echo $category->category_nicename; ?></li>
    
    						<?php endforeach; ?>
Viewing 1 replies (of 1 total)
  • The topic ‘How to loop through categories and change their URLs?’ is closed to new replies.