0

This question is an exact duplicate of:

Currently posts in category page arranged by last added, this is the code, please how to make it random

if (is_category()) {
        $categories = array(get_query_var('cat'));
        $subcats = get_categories(array('child_of' => get_query_var('cat')));
        if ($subcats) {
            foreach ($subcats as $subcat) {
                array_push($categories, $subcat->cat_ID);
            }
        }

        if (of_get_option('show_repins') != 'disable') {            
            $args = array(
                'category__in' => $categories,
                'paged' => $paged
            );
        } else {
            $args = array(
                'category__in' => $categories,
                'paged' => $paged,
                'meta_query' => array(
                    'relation' => 'OR',
                    array(
                        'key' => '_Original Post ID',
                        'compare' => 'NOT EXISTS'
                    ),
                    array(
                        'key' => '_Original Post ID',
                        'value' => 'deleted'
                    )
                )
            );  
        }
        query_posts($args); 
    }

marked as duplicate by Tom J Nowell Jun 28 '17 at 15:41

This question was marked as an exact duplicate of an existing question.

0

query_posts() allows for an argument called orderby, there you can provide how you want your posts sorted. So a solution could look like this

$args['orderby'] = 'rand';
query_posts($args);

For a full list and explanation of the query arguments, check WordPress Developer Resources on WP_Query

  • is it right? array( 'key' => '_Original Post ID', 'value' => 'deleted' ) ) ); } $args['orderby'] = 'rand'; query_posts($args); } – user3415122 Jun 28 '17 at 15:36
  • @user3415122 Yes sounds right – kero Jun 29 '17 at 8:49

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