• Hi!

    I need to show random posts in my frontpage, but by doing wp_query not working argument orderby => ‘rand’. How can I fix this problem?

Viewing 4 replies - 1 through 4 (of 4 total)
  • Can you post the code where you use these order by argument so I can assist you better?

    Moderator Steven Stern (sterndata)

    (@sterndata)

    Volunteer Forum Moderator

    Use print_r to output the results of the query. If they change from fetch to fetch but the front page does not change, then the issue is that the query is working but the page has been cached and you’re seeing the same (old)result over and over. If so, the solution is to exclude that page from your cache — the method of doing so depends on the caching plugin(s) you’re using.

    Thread Starter rondos

    (@rondos)

    Hi! Still I have not resolved this problem. Orderby rand not working. There is my query:

    $args = array(
    'cat' => 2,
    'posts_per_page' => 12,
    'orderby'   => 'rand'
    );
    $query = new WP_Query( $args );

    I used print_r to check for changes, but result all time same. There is begining of my query print_r result:
    WP_Query Object ( [query] => Array ( [cat] => 2 [posts_per_page] => 12 [orderby] => rand ) [query_vars] => Array ( [cat] => 2 [posts_per_page] => 12 [orderby] => meta_value [error] => [m] => [p] => 0

    • This reply was modified 7 years, 7 months ago by rondos.
    Moderator bcworkz

    (@bcworkz)

    See how the query_vars[orderby] became meta_value? Something is hooked into the query process and altering the orderby. I get random posts in a category with your query on my site, so there’s nothing wrong with that.

    You may need to do the deactivate all plugins and switch to a default theme process. Restore each extension one at a time until the problem returns. The last activated extension is altering your query.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘orderby => ‘rand’ (NOT WORKING)’ is closed to new replies.