588 | | $sql = "SELECT DISTINCT meta_key |
589 | | FROM $wpdb->postmeta |
590 | | WHERE meta_key NOT BETWEEN '_' AND '_z' |
591 | | HAVING meta_key NOT LIKE %s |
592 | | ORDER BY meta_key |
593 | | LIMIT %d"; |
594 | | $keys = $wpdb->get_col( $wpdb->prepare( $sql, $wpdb->esc_like( '_' ) . '%', $limit ) ); |
| 588 | |
| 589 | /** |
| 590 | * Filter the number of rows to retrieve from the database when searching |
| 591 | * for custom field names. |
| 592 | * |
| 593 | * @since 4.4.0 |
| 594 | * |
| 595 | * @param int $limit Number of rows to retrieve. Default 1000. |
| 596 | */ |
| 597 | $row_limit = apply_filters( 'postmeta_form_row_limit', 1000 ); |
| 598 | |
| 599 | $keys = array(); |
| 600 | $offset = 0; |
| 601 | while( count( $keys ) < $limit ) { |
| 602 | $sql = "SELECT DISTINCT meta_key |
| 603 | FROM $wpdb->postmeta |
| 604 | LIMIT %d,%d"; |
| 605 | $maybe_keys = $wpdb->get_col( $wpdb->prepare( $sql, $offset, $row_limit ) ); |
| 606 | |
| 607 | foreach ( $maybe_keys as $key ) { |
| 608 | if ( 0 !== strpos( $key, '_' ) ) { |
| 609 | $keys[] = $key; |
| 610 | } |
| 611 | |
| 612 | if ( count( $keys ) >= $limit ) { |
| 613 | break 2; |
| 614 | } |
| 615 | } |
| 616 | |
| 617 | if ( count( $maybe_keys ) < $row_limit ) { |
| 618 | break; |
| 619 | } |
| 620 | |
| 621 | $offset += $row_limit; |
| 622 | } |
| 623 | |