vendredi 19 février 2016

How to random only on 10 first recents posts?

I am facing of a client request, he has 100 products with pagination ( 10 per page), he wants only random on the first 10 products and for the rest of the pages no random ( for others paginations other than 1 )

I have this query :

$args = array(
    'post_type' => array('products'),
    'paged'=> ( get_query_var('paged') ? get_query_var('paged') : 1 ),
);
$products = new Wp_Query($argss);
... Loop here ...
... End loop ...
... Pagination ...

Products displays well, pagination works, only i ask myself how to achieve this goal. If i use :

if( $paged == 1 ) $args['orderby'] = 'rand';

It will random on the first page but he will pick other products other than the first 10 product, the goal is to only random the first 10 products on home search page without picking up the others.

Thanks for your help.




Aucun commentaire:

Enregistrer un commentaire