vendredi 1 avril 2016

Wordpress, random product only on home search page

I have a custom wordpress search page with page navigation numbers, my client asks me to random products on page 1 but not for others, but all products displayed randomly on home page should not displayed on others pages.

For the query i have this code :

$args = array(
  'post_type' => 'products',
  'paged' => ( get_query_var('paged') ? get_query_var('paged') : 1 )
)   

and for the random :

if( $args['paged'] == 1) {
    $args['orderby'] = 'rand';
} else {
    $args['order'] = 'DESC':
}

the results are there when i do a search, and first page random well, but some products that are already displayed on home page because of the random are also displayed on others pages (ex : page 2 ).

The aim is not display products that are already displayed on home page.

I already do something similar :

if( $page == 1 ) shuffle($r->posts);

But it shuffle only first the 10 products on page 1, and others products on others pages never display on page 1.

Sorry for bad english, and may you help me please ?

Thanks




Aucun commentaire:

Enregistrer un commentaire