Display number of posts in category since last visit
-
Hi
I want to display the number of new posts in three separate categories since the users last visit. When the user reads the posts of one category, I create a cookie with the date of their visit. Next time he visits I create a filter which filters out the posts which were published after the users visit. However, when I try to combine it with a query category, it displays the number of all of the posts instead of just the posts from the category current.
I’m guessing that the posts_where hook overrides the query and it displays the number of all of the new articles.
Here is the code, please help me, how can I solve this issue.
function filter_a() { $where .= " AND post_date >='" . date('Y-m-d H:i:s', $_COOKIE['a'] / 1000) . "'"; return $where; } function notifications_since($notifcateg) { switch($notifcateg){ case 'a': add_filter('posts_where','filter_a'); break; } $query = array ( 'category_name' => $notifcateg ); $queryObject = new WP_Query($query); $postcount = $queryObject->post_count; remove_all_filters('posts_where'); wp_reset_postdata(); return $post_count;
}
- The topic ‘Display number of posts in category since last visit’ is closed to new replies.