Support Forum

Including moderators in "Top Posters" stats

GO gorky5
gorky5
Member

Hi. If I make someone a moderator, and they were in the Top Posters forum stats, their name disappears from the list.

I know the Moderators have their own list which includes their post counts, but I’d like the option to have them also in the Top Posters list, especially if they’re in both the Moderators and and Members user groups.

Is there a way to include forum moderators in the “Top posters” section of the stats panel? If not, can I suggest it becomes an option in General Display Settings?

12 Answers

New Answer

MP Mr Papa
Mr Papa
Member

you can filter the query to include moderators and admins if you like…

use filter:  sph_stats_top_posters_query

which returns an object…  edit the object where element to remove the admin=0 and moderator=0 part of it…

holler if you need more help..

GO gorky5
gorky5
Member

holler if you need more help..

Yes please! Could I get some step-by-step instructions? I’m not overly familiar with php, and I don’t know where I find that filter.

Also, will changes get overwritten with a SP update or can I put them in a child theme?

MP Mr Papa
Mr Papa
Member

to your spFunctions.php file, add this:

add_filter(‘sph_stats_top_posters_query’, ‘my_stats_query’);
function my_stats_query($query) {
    $query->where = ‘admin=0 AND posts > -1’;
    return $query;
}

that will add in moderators now when the stats run… remember, they are cached, so may take an hour to show up…

GO gorky5
gorky5
Member

Thanks v much. I ran the sph_stats_cron hook and the changes showed up just fine.

GO gorky5
gorky5
Member

Hi again. I added that code to the spFunctions.php file in my child theme. If I manually run the sph_stats_cron hook in Cron Inspector the moderators appear in the Top Posters list.

However, when the cron job runs again at its usual time (every 3600 seconds) it goes back to displaying only standard members, not members and moderators.

Is there something else I need to do to get this working consistently? What is resetting the list?

MP Mr Papa
Mr Papa
Member

wouldnt have thought so, but maybe the sp theme isnt loaded by wp cron (which actually makes sense)…

so try moving it to your wp theme functions.php file…

GO gorky5
gorky5
Member

Thank you! Having it in the theme functions file worked.

YS Yellow Swordfish
Yellow Swordfish
Member

That’s good news. Thanks for the update.
It’s an interesting condition you met there. The Cron tasks can be actioned by loading a page from the back or the front end and depending on what is being run will determine whether any SP theme code is loaded or not. We will remember this wrinkle for the future…

GO gorky5
gorky5
Member

Further update: It did work for a few hours, but then something (presumably a cron task) changed and the list went back to just showing normal members.

The code is still in my theme functions file but now it doesn’t seem to do anything at all. Very strange.

MP Mr Papa
Mr Papa
Member

not sure how it could stop after a few hours…  wp cron tasks dont change, they just execute… by theme functions.php you mean wp, right?  did you remove it from the sp theme (you should)…

GO gorky5
gorky5
Member

It confused me too. Oddly when I logged on this morning it was behaving as it should do, with mods and members both in the list again, so I’m not sure what went wrong before!

Yes, I put the code in WP theme functions, and removed it from my SP child theme. All is good now – fingers crossed it stays that way!

Sorry to go back and forth on this, and thanks for your patience.

YS Yellow Swordfish
Yellow Swordfish
Member

No worries. I hope it holds now and behaves itself…