jeudi 24 mars 2016

Recently viewed non cookie version

I've built a widget where I'm trying to display recently viewed recipes.

Inside my single-recipe page I've added this code:

update_post_meta( $post->ID, 'mp_last_viewed', current_time('mysql') );

Inside my widget, I use this

$params = array(
        'post_type'      => 'recipes',
        'posts_per_page' => $limit,
        'post_status'    => 'publish',
        'offset'         => '$offset,
        'orderby'        => 'meta_value',
        'order'          => 'DESC',
        'meta_key'       => 'mp_last_viewed',
        'post__not_in'   => 'array($post_id)',
     );

     $query_recipes = new WP_Query($params);

This displays a list of latest recipes that every visitor looked at.

Now I'd like to limit this list to the current visitor only, without using cookies. And if possible add an expiration date of 24h. Is this even possible and how? Or should I go for cookies instead? If I do, any links to tutorials?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire