Hi @cinghaman,
Next release will include a filter hook that you can use for this. No ETA though so feel free to add this change manually to the plugin if this is something you need right away.
Thread Starter
Robin
(@cinghaman)
@hcabrera Thanks yup will use it at the moment, thanks
Thread Starter
Robin
(@cinghaman)
Hi @hcabrera
I tried adding this filter let me know if it is wrong as i don’t see any change?
/*
* filter for most popular
*/
$terms = get_terms(
$taxonomy,
array(
‘number’ => 1,
)
);
apply_filters( ‘wpp_post_terms’, $terms );
Assuming you already modified the src/Output.php file as shown on my previous comment (it sounds like you didn’t), then no I don’t see anything wrong with your code – except for the fact that it won’t work as you expect it.
The get_terms() function returns all of the terms under a given taxonomy (eg. all of the terms that are Categories) not just the ones related to each post (read the documentation for more details.)
Instead of that, 1) make sure you add the modification to src/Output.php exactly the same way as seen on the link I shared above, then 2) add this to your theme’s functions.php file:
/**
* Have WordPress Popular Posts display only one category.
*/
add_filter('wpp_post_terms', function($terms){
return array_slice($terms, 0, 1);
});