Shortcode to show thumbnail and link for 3 random posts

Starting from WordPress version 4.5, you can use RAND(seed) with the orderby parameter.

However, when the value is simply RAND (i.e. the uppercase of rand), WP_Query ignores it and defaults to the default sorting (which is by the post date).

I’ve confirmed that by inspecting the $query->request:

  1. With 'orderby' => 'RAND', the ORDER BY clause is ORDER BY wp_posts.post_date DESC.

  2. With 'orderby' => 'rand', the ORDER BY clause is ORDER BY RAND().

So the solution is simple: Always use rand, unless you want to use a seed.

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)