Hi there!
I am using popularity contest for wordpress in a self-hosted website.
Is it possible to the popularity contest only track the posts from a specific category?
Thanks in advance.
Hi there!
I am using popularity contest for wordpress in a self-hosted website.
Is it possible to the popularity contest only track the posts from a specific category?
Thanks in advance.
Though I haven't worked with popularity-contest in a little while, I think this should work:
/**
* Define the categories to be tracked
*/
$GLOBALS['pc_track_cats'] = array(1,3,5,8); // alternately, category slugs can be used as well
/**
* Check the content each time it is called to see if we're in our target cat
* if not, remove the popularity-contest filter
*
* @param string $the_content
* @return string
*/
function my_check_pc($the_content) {
if (!in_category($GLOBALS['pc_track_cats'])) {
remove_filter('the_content', 'akpc_content_pop');
}
return $the_content;
}
add_filter('the_content', 'my_check_pc', 1);
/**
* Replace the popularity contest filter after the content has been run
*
* @param string $the_content
* @return string
*/
function my_replace_pc($the_content) {
add_filter('the_content', 'akpc_content_pop');
return $the_content;
}
add_filter('the_content', 'my_replace_pc', 9999);