Adding sticky class to most viewed posts
-
I’m trying to write a fucntion in functions.php that promotes a post to featured depending on how many times has been viewed. For the views count I’m using a plugin method (WordPress Popular Posts). The theme is based on Roots.
function promote_post($promoted) { global $post; foreach(($post->ID) as $promoted ){ wpp_get_views($post->ID); } if (is_home() && (wpp_get_views($post->ID) > 2)){ stick_post($promoted); } } add_filter('post_class', 'promote_post');
I’m not able to loop through all the posts and set the sticky class according to the condition. The error I get is: Invalid argument supplied for foreach().
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘Adding sticky class to most viewed posts’ is closed to new replies.