I'm trying to write a function in functions.php that promotes a post to featured depending on how many times has been viewed. For the views I'm using a plugin method. Still I'm not able to loop through all the posts and set the sticky class.
function promote_post($viewed) {
global $post;
foreach($post->ID as $viewed){
$post_views = wpp_get_views($post->ID);
}
if (is_home() && ($post_views > 2)){
stick_post($viewed);
} else {
unstick_post($viewed)
}
}
add_filter('post_class', 'promote_post');
I'm confident that I'm not using the foreach as it should be. I'd appreciate some directions thus to sharpen my PHP skills.
Thanks beforehand.
foreach($viewed as $post)? – toscho♦ Oct 3 '12 at 21:43get_the_ID()instead. Won't change anything, but there's a 1% chance that you got a typo somewhere. – kaiser Oct 4 '12 at 6:37function promote_post($classes) { global $post; if (is_home() && wpp_get_views($post->ID) > 10){ stick_post(get_the_ID()); } else {unstick_post(get_the_ID()); } return $classes; } add_filter('post_class', 'promote_post');– user1672895 Oct 4 '12 at 21:44