Very briefly tested as I am on holiday tomorrow, but try this
$r = array(
'post_type' =>bbp_get_reply_post_type(),
'post_parent' => $topic_id,
'author__not_in' => array( $author_id)
);
$reply_posts = new WP_Query($r);
$count = $reply_posts->post_count;
Thanks Robin, tested, works perfectly, your help is very much appreciated.
Great – glad you are fixed
Just a little follow up question … I’m looking at modifying my “reward” system, ignoring the number of replies and simply rewarding based on forum engagement. So a reward is triggered when a user creates a new topic or posts a reply ( capped at one reward per day, to avoid spam reward-mining )
What should I do?
1. Create two reward functions, hook one to bbp_new_topic and hook the other to bbp_new_reply ?
2. Create one reward function and hook it to some kind of combo “bbp_all_user_engagement” thing, if that exists?
3. Something different?
Cheers!
You can achieve this without raw SQL by looping through the replies and filtering out the author’s own ones. Something like this:
$reply_count = 0;
$replies = bbp_get_all_child_ids( $topic_id, bbp_get_reply_post_type() );
if ( ! empty( $replies ) ) {
foreach ( $replies as $reply_id ) {
if ( get_post_field( ‘post_author’, $reply_id ) != $author_id ) {
$reply_count++;
}
}
}
This way you count only replies not made by the topic author. Then you can compare $reply_count with your threshold to trigger the reward.
It’s lightweight, avoids direct SQL, and keeps everything inside bbPress/WordPress functions.
so when a user posts a topic or they reply to a topic, you want to give them a reward immediately, but then not give them a further reward for the remainder of that day ie give them a reward for the first post they make each day.
and not use the previous reward system
Yes?
Hi Robin, yes that’s correct. The previous system worked fine but was not really encouraging forum participation so it will be replaced.
The daily-limit is handled by a simple flag in the usermeta table, all good.
I’m really just asking if there exists a combo version of bbp_new_topic and bbp_new_reply for me to hook onto, or if I should simply hook onto both of those, separately.
eg.
add_action( 'bbp_new_topic' , 'my_reward_function' );
add_action( 'bbp_new_reply' , 'my_reward_function' );
function my_reward_function() {
// check daily-limit flag, bail if set to today's date
// update the user's reward info
// set daily-limit flag to today's date
}
Hi @markkavin,
Thanks! Much appreciated!
no combo, so just hook separately 🙂