WordPress.org

Make WordPress Core

Ticket #18979: meta_form.diff

File meta_form.diff, 1.7 KB (added by takayukister, 3 years ago)

a patch for meta_form()

  • wp-admin/includes/meta-boxes.php

     
    430430                unset( $metadata[ $key ] ); 
    431431} 
    432432list_meta( $metadata ); 
    433 meta_form(); ?> 
     433meta_form( $post->post_type ); ?> 
    434434</div> 
    435435<p><?php _e('Custom fields can be used to add extra metadata to a post that you can <a href="http://codex.wordpress.org/Using_Custom_Fields" target="_blank">use in your theme</a>.'); ?></p> 
    436436<?php 
  • wp-admin/includes/template.php

     
    491491 * 
    492492 * @since 1.2.0 
    493493 */ 
    494 function meta_form() { 
     494function meta_form( $post_type = '' ) { 
    495495        global $wpdb; 
     496 
    496497        $limit = (int) apply_filters( 'postmeta_form_limit', 30 ); 
    497         $keys = $wpdb->get_col( " 
    498                 SELECT meta_key 
    499                 FROM $wpdb->postmeta 
    500                 GROUP BY meta_key 
    501                 HAVING meta_key NOT LIKE '\_%' 
    502                 ORDER BY meta_key 
    503                 LIMIT $limit" ); 
     498 
     499        $q = "SELECT meta_key FROM $wpdb->postmeta"; 
     500 
     501        if ( ! empty( $post_type ) && post_type_exists( $post_type ) ) 
     502                $q .= $wpdb->prepare( " INNER JOIN $wpdb->posts ON post_id = ID WHERE post_type LIKE %s", $post_type ); 
     503 
     504        $q .= " GROUP BY meta_key HAVING meta_key NOT LIKE '\_%' ORDER BY meta_key LIMIT $limit"; 
     505 
     506        $keys = $wpdb->get_col( $q ); 
     507 
     508        $keys = apply_filters( 'postmeta_form_keys', $keys, $post_type ); 
     509 
    504510        if ( $keys ) 
    505                 natcasesort($keys); 
     511                natcasesort( $keys ); 
    506512?> 
    507513<p><strong><?php _e( 'Add New Custom Field:' ) ?></strong></p> 
    508514<table id="newmeta">