How can I exclude visited posts from a loop? I have a loop of recent posts on a single post page that excludes the current post and I want to extend the amount of times users browse by filtering out the ones they’ve already seen. Here’s the basic loop.
<?php
$featured_post_id = get_the_ID();
global $post;
$args = array('cat' => '9', 'posts_per_page' => 5, 'post__not_in' => array($featured_post_id));
$my_query = new WP_Query($args);
if ( $my_query->have_posts() ) : ?>
This is a heavier question than you think. You’ll need to do quite a bit:
$featured_post_id
to pass it in thepost__not_in
parameterI won’t deal with the first two issues … setting and reading cookies isn’t a WordPress question and you can easily find that information with a simple Google search.
But for the rest of it, your code will look something like this: