I have category page where I display articles in a random way. There's a taxonomy by city in my articles.

So at the top of my page, there are some links in order to display the category with taxonomy filter.

At the beginning, my links looked like :

<a href="<?php
$category_id = get_query_var('cat');
echo get_category_link( $category_id );

<a href="<?php
$category_id = get_query_var('cat');
echo get_category_link( $category_id );

etc ..

So I could stay in the same category, and apply my filter.

With the random behaviour, I had to add this to call my articles :

<? query_posts(array(
'orderby' => 'rand'
if (have_posts()) : while (have_posts()) : the_post();

But now my filters don't work anymore.

I'd like to avoid to call a specific category because I have very much categories. And every time I need to have my cities-links at the top. So if I could use the same template, it would be more handy.

I'm not very good with php.... Does someone has an idea ?

I thank you in advance for your help

  • What filter? Where is the code? Also, don't use query_posts.
    – s_ha_dum
    Nov 22, 2013 at 4:17

1 Answer 1


Better to use get_posts. This is how you can use "rand"

$args = array( 'orderby' => 'rand' );
$rand_posts = get_posts( $args );
foreach ( $rand_posts as $post ) : 
    setup_postdata( $post ); ?>
    <!-- Do the things here... -->
<?php endforeach; 
  • Lone link is considered a poor answer (see help > deleted answers) since it is meaningless by itself and target resource is not guaranteed to be alive in the future. Please explain how and why it answers the question.
    – Rarst
    Nov 22, 2013 at 10:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.