bbp_bump_forum_topic_count( int $forum_id, int $difference = 1, bool $update_ancestors = true )
Bump the total topic count of a forum
Description
Parameters
- $forum_id
-
(Optional) Forum id.
- $difference
-
(Optional) Default 1
Default value: 1
- $update_ancestors
-
(Optional) Default true
Default value: true
Return
(int) Forum topic count
Source
File: bp-forums/forums/functions.php
1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 | function bbp_bump_forum_topic_count( $forum_id = 0, $difference = 1, $update_ancestors = true ) { // Get some counts $forum_id = bbp_get_forum_id( $forum_id ); $topic_count = bbp_get_forum_topic_count( $forum_id , false, true ); $total_topic_count = bbp_get_forum_topic_count( $forum_id , true, true ); // Update this forum id update_post_meta( $forum_id , '_bbp_topic_count' , (int) $topic_count + (int) $difference ); update_post_meta( $forum_id , '_bbp_total_topic_count' , (int) $total_topic_count + (int) $difference ); // Check for ancestors if ( true === $update_ancestors ) { // Get post ancestors $forum = get_post( $forum_id ); $ancestors = get_post_ancestors( $forum ); // If has ancestors, loop through them... if ( ! empty ( $ancestors ) ) { foreach ( ( array ) $ancestors as $parent_forum_id ) { // Get forum counts $parent_topic_count = bbp_get_forum_topic_count( $parent_forum_id , false, true ); $parent_total_topic_count = bbp_get_forum_topic_count( $parent_forum_id , true, true ); // Update counts update_post_meta( $parent_forum_id , '_bbp_topic_count' , (int) $parent_topic_count + (int) $difference ); update_post_meta( $parent_forum_id , '_bbp_total_topic_count' , (int) $parent_total_topic_count + (int) $difference ); } } } return (int) apply_filters( 'bbp_bump_forum_topic_count' , (int) $total_topic_count + (int) $difference , $forum_id , (int) $difference , (bool) $update_ancestors ); } |
Changelog
Version | Description |
---|---|
bbPress (r3825) | Introduced. |
Questions?
We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.