| @@ -27,12 +27,17 @@ | ||
| 27 | 27 | wp_send_json_error( 'Forum title cannot be empty.' ); |
| 28 | 28 | } |
| 29 | 29 | |
| 30 | 30 | $args = [ |
| 31 | - 'post_type' => 'forum', | |
| 32 | - 'post_parent' => 0, | |
| 31 | + 'post_type' => 'forum', | |
| 32 | + 'post_parent' => 0, | |
| 33 | + 'posts_per_page' => 1, | |
| 34 | + 'fields' => 'ids', | |
| 35 | + 'update_post_meta_cache' => false, | |
| 36 | + 'update_post_term_cache' => false, | |
| 33 | 37 | ]; |
| 34 | 38 | |
| 39 | + // Only the count is needed. | |
| 35 | 40 | $query = new \WP_Query( $args ); |
| 36 | 41 | $total = $query->found_posts; |
| 37 | 42 | $add = 2; |
| 38 | 43 | $order = $total + $add; |
| @@ -91,12 +96,17 @@ | ||
| 91 | 96 | } |
| 92 | 97 | |
| 93 | 98 | // Get order for the new sub-forum. |
| 94 | 99 | $args = [ |
| 95 | - 'post_type' => 'forum', | |
| 96 | - 'post_parent' => $parent_forum_id, | |
| 100 | + 'post_type' => 'forum', | |
| 101 | + 'post_parent' => $parent_forum_id, | |
| 102 | + 'posts_per_page' => 1, | |
| 103 | + 'fields' => 'ids', | |
| 104 | + 'update_post_meta_cache' => false, | |
| 105 | + 'update_post_term_cache' => false, | |
| 97 | 106 | ]; |
| 98 | 107 | |
| 108 | + // Only the count is needed. | |
| 99 | 109 | $query = new \WP_Query( $args ); |
| 100 | 110 | $total = $query->found_posts; |
| 101 | 111 | $order = $total + 1; |
| 102 | 112 | |