Show terms of a random taxonomy

0

I'm displaying all categories with their respective images, as per the code below:

<?php
categorias = apply_filters('taxonomy-images-get-terms', '', array( 'taxonomy' => 'category') );
foreach($categorias as $key => $categoria):             
    if($key < 6):
    ?>
    <div class="box">
        <a href="<?php echo get_category_link($categoria->term_id);?>">
            <figure>
                <?php echo wp_get_attachment_image($categoria->image_id,''); ?>
            </figure>
            <img src="<?php bloginfo('template_directory');?>/images/icones/plus.png" class="plus-icone" alt="">    
            <figcaption class="titulo-foto-categoria"><?php echo $categoria->name;?></figcaption>
        </a>
    </div>
    <?php
    endif;
endforeach;?>

The apply_filters function was used to display the category image, so far as I could find on the internet, only this way it can be done. So I noticed this function shows all results in alphabetical order and I need to show them randomly or by date.

Is it possible to do this?

    
asked by anonymous 27.07.2017 / 22:52

1 answer

1

It seems like apply_filters is always returning an array there, so just reorder the array using shuffle to get scrambled:

$categorias = apply_filters('taxonomy-images-get-terms', '', array( 'taxonomy' => 'category') );

shuffle( $categorias );

foreach ( $categorias as $key => $categoria ) : //etc
    
28.07.2017 / 02:50