680 | | $sql = "SELECT DISTINCT meta_key |
681 | | FROM $wpdb->postmeta |
682 | | WHERE meta_key NOT BETWEEN '_' AND '_z' |
683 | | HAVING meta_key NOT LIKE %s |
684 | | ORDER BY meta_key |
685 | | LIMIT %d"; |
686 | | $keys = $wpdb->get_col( $wpdb->prepare( $sql, $wpdb->esc_like( '_' ) . '%', $limit ) ); |
| 679 | |
| 680 | if ( $post instanceof WP_Post && isset( $post->ID ) && is_int( $post->ID ) && $post->ID > 0 ){ |
| 681 | $post_id = (int) $post->ID; |
| 682 | $sql = "SELECT DISTINCT meta_key |
| 683 | FROM $wpdb->postmeta |
| 684 | WHERE post_id = %d AND meta_key NOT BETWEEN '_' AND '_z' |
| 685 | HAVING meta_key NOT LIKE %s |
| 686 | LIMIT %d"; |
| 687 | |
| 688 | $keys = $wpdb->get_col( $wpdb->prepare( $sql, $post_id, $wpdb->esc_like( '_' ) . '%', $limit ) ); |
| 689 | } else { |
| 690 | $sql = "SELECT DISTINCT meta_key |
| 691 | FROM $wpdb->postmeta |
| 692 | WHERE meta_key NOT BETWEEN '_' AND '_z' |
| 693 | HAVING meta_key NOT LIKE %s |
| 694 | LIMIT %d"; |
| 695 | |
| 696 | $keys = $wpdb->get_col( $wpdb->prepare( $sql, $wpdb->esc_like( '_' ) . '%', $limit ) ); |
| 697 | } |
| 698 | |