| 2604 | // Comment query |
| 2605 | /** |
| 2606 | * Easy call |
| 2607 | * $args['comment_count'] = n; n >= 0 |
| 2608 | * |
| 2609 | * Extended call |
| 2610 | * $args['comments']['count'] = n; n >= 0 |
| 2611 | * |
| 2612 | * Optional: |
| 2613 | * $args['comments']['compare'] = Compare; Compare: =, !=, >, >=, <, <= |
| 2614 | */ |
| 2615 | if ( isset( $q['comment_count']) ) { |
| 2616 | $where .= " AND {$wpdb->posts}.comment_count = " . absint($q['comment_count']); |
| 2617 | } elseif ( isset( $q['comments']['count'])) { |
| 2618 | $where .= " AND ( {$wpdb->posts}.comment_count "; |
| 2619 | |
| 2620 | // Do a check for operators |
| 2621 | // Taken from WP_Date_Query::get_compare() |
| 2622 | $compare_operators = array( '=', '!=', '>', '>=', '<', '<=' ); |
| 2623 | if ( isset( $q['comments']['compare'] ) && in_array( $q['comments']['compare'], $compare_operators ) ) { |
| 2624 | $where .= $q['comments']['compare']; |
| 2625 | } else { |
| 2626 | // Fallback to equal sign |
| 2627 | $where .= "="; |
| 2628 | } |
| 2629 | // Now add the count |
| 2630 | $where .= " " . absint($q['comments']['count']); |
| 2631 | |
| 2632 | $where .= ')'; // Close |
| 2633 | } |
| 2634 | |