| @@ -29,16 +29,25 @@ | ||
| 29 | 29 | |
| 30 | 30 | $forum_id = ! empty( $_POST['forum_id'] ) ? absint( $_POST['forum_id'] ) : 0; |
| 31 | 31 | $topic_author = bbp_get_current_user_id(); |
| 32 | 32 | |
| 33 | - $parent_item = get_children( [ | |
| 34 | - 'post_parent' => $forum_id, | |
| 35 | - 'post_type' => 'topic', | |
| 33 | + if ( ! bbp_is_forum( $forum_id ) ) { | |
| 34 | + wp_send_json_error( 'Invalid forum.' ); | |
| 35 | + } | |
| 36 | + | |
| 37 | + // Only the count is needed. | |
| 38 | + $parent_items = new WP_Query( [ | |
| 39 | + 'post_parent' => $forum_id, | |
| 40 | + 'post_type' => 'topic', | |
| 41 | + 'post_status' => 'any', | |
| 42 | + 'posts_per_page' => 1, | |
| 43 | + 'fields' => 'ids', | |
| 44 | + 'update_post_meta_cache' => false, | |
| 45 | + 'update_post_term_cache' => false, | |
| 36 | 46 | ] ); |
| 37 | 47 | |
| 38 | 48 | $add = 2; |
| 39 | - $order = count( $parent_item ); | |
| 40 | - $order = $order + $add; | |
| 49 | + $order = (int) $parent_items->found_posts + $add; | |
| 41 | 50 | |
| 42 | 51 | // Create topic object |
| 43 | 52 | $topic_data = apply_filters( 'bbp_new_topic_pre_insert', [ |
| 44 | 53 | 'post_author' => $topic_author, |