@@ 112-133 (lines=22) @@ | ||
109 | * @param int $max_id Maximum post ID. |
|
110 | * @return int Number of posts. |
|
111 | */ |
|
112 | public function post_count( $status = null, $min_id = null, $max_id = null ) { |
|
113 | global $wpdb; |
|
114 | ||
115 | $where = ''; |
|
116 | ||
117 | if ( $status ) { |
|
118 | $where = "post_status = '" . esc_sql( $status ) . "'"; |
|
119 | } else { |
|
120 | $where = '1=1'; |
|
121 | } |
|
122 | ||
123 | if ( ! empty( $min_id ) ) { |
|
124 | $where .= ' AND ID >= ' . intval( $min_id ); |
|
125 | } |
|
126 | ||
127 | if ( ! empty( $max_id ) ) { |
|
128 | $where .= ' AND ID <= ' . intval( $max_id ); |
|
129 | } |
|
130 | ||
131 | // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared |
|
132 | return $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->posts WHERE $where" ); |
|
133 | } |
|
134 | ||
135 | /** |
|
136 | * Retrieve the posts with a particular post status. |
|
@@ 293-314 (lines=22) @@ | ||
290 | * @param int $max_id Maximum comment ID. |
|
291 | * @return int Number of comments. |
|
292 | */ |
|
293 | public function comment_count( $status = null, $min_id = null, $max_id = null ) { |
|
294 | global $wpdb; |
|
295 | ||
296 | $comment_approved = $this->comment_status_to_approval_value( $status ); |
|
297 | ||
298 | if ( false !== $comment_approved ) { |
|
299 | $where = "comment_approved = '" . esc_sql( $comment_approved ) . "'"; |
|
300 | } else { |
|
301 | $where = '1=1'; |
|
302 | } |
|
303 | ||
304 | if ( ! empty( $min_id ) ) { |
|
305 | $where .= ' AND comment_ID >= ' . intval( $min_id ); |
|
306 | } |
|
307 | ||
308 | if ( ! empty( $max_id ) ) { |
|
309 | $where .= ' AND comment_ID <= ' . intval( $max_id ); |
|
310 | } |
|
311 | ||
312 | // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared |
|
313 | return $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->comments WHERE $where" ); |
|
314 | } |
|
315 | ||
316 | /** |
|
317 | * Translate a comment status to a value of the comment_approved field. |