orderby
does not accept the values ASC
or DESC
. These are acceptable values for the parameter order
. Changing 'orderby' => 'rand'
to 'order' => 'ASC'
should be sufficient and should by rule work
As already pointed out,
if (have_posts() ):
should be
if ($the_query->have_posts() ):
Apart from that little discrepancy, you code have to work
It case this does not solve your problem, look in your functions.php for any instance of pre_get_posts
. The reason for my thinking is, pre_get_posts
does not only alter the main query, but also all instances of WP_Query
. You have to include the conditional tag is_main_query()
to target the main query only, otherwise pre_get_posts
will interfere with instances of WP_Query
For additional resources: