Support » Developing with WordPress » random of posts don’t worked

  • i use this code in my front-page.php to display a random post but it don’t worked.

    $args_blog = array( 'post_type' => 'post','posts_per_page' => '2','orderby'=>'rand',);
    $args = new WP_Query($args_blog);
    echo "<pre>";
    var_dump($args);
    echo "</pre>";

    in addition when i display $args with var_dump i discover the request didn’t used with orderby Random()
    "SELECT SQL_CALC_FOUND_ROWS wp_posts.ID FROM wp_posts WHERE 1=1 AND wp_posts.post_type = 'post' AND (wp_posts.post_status = 'publish' OR wp_posts.post_status = 'private') ORDER BY wp_posts.menu_order ASC LIMIT 0, 2"
    how can correct the code to display the random?

Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    Your code results in the SQL RAND() function when used on my site. You must have a plugin or your theme somehow altering the query in a way that negates your orderby argument. If you deactivate all plugins and switch to a twenty* theme, then temporarily place your code on a template, you’ll find that RAND() will be used in the query.

    Start restoring your configuration, one module at a time. When RAND() disappears again, the last activated module is negating your orderby argument.

Viewing 1 replies (of 1 total)
  • You must be logged in to reply to this topic.