[wp-trac] [WordPress Trac] #54343: set custom name for metadata value in custom-fileds metabox select box

WordPress Trac noreply at wordpress.org
Fri Oct 29 18:44:52 UTC 2021


#54343: set custom name for metadata value in custom-fileds metabox select box
-----------------------------+-----------------------------
 Reporter:  myousefi08       |      Owner:  (none)
     Type:  feature request  |     Status:  new
 Priority:  normal           |  Milestone:  Awaiting Review
Component:  General          |    Version:  5.8.1
 Severity:  normal           |   Keywords:
  Focuses:                   |
-----------------------------+-----------------------------
 I use postmeta_form_keys filter to add some extra custom metadata to
 custom-fileds metabox.
 but i want to set name for metadata.
 Beacuase i use persian language, it isnt good to set persian letter as
 metadata.
 its better i can set a name and value for each metadata.
 for example in postmeta_form_keys callback:

 {{{
 function filter_function_name_1552( $keys, $post ){
     if($post->post_type == 'car') {
         $keys['قیمت'] = 'regular_price';
     }
         return $keys;
 }
 }}}
 that 'قیمت' is custom name to display in meta select option text and
 regular_price is meta key (option value to save and access)

 i dont know this restrictions and how to handle it. but its my idea

 in wp-admin/template.php line ~693
 change $keys to Associative arrays (import every value as key too) to
 support submitted metadatas

 {{{
 $keys = $wpdb->get_col(
         $wpdb->prepare(
         "SELECT DISTINCT meta_key
         FROM $wpdb->postmeta
         WHERE meta_key NOT BETWEEN '_' AND '_z'
         HAVING meta_key NOT LIKE %s
         ORDER BY meta_key
         LIMIT %d",
         $wpdb->esc_like( '_' ) . '%',
         $limit
         )
         );

         foreach($keys as $index=>$key){
             unset($keys[$index]);
             $keys[$key] = $key;
         }
 }}}

 and in same file line ~734
 add $index and change $key with $index in foreach


 {{{
 foreach ( $keys as $index => $key ) {
         if ( is_protected_meta( $key, 'post' ) || ! current_user_can(
 'add_post_meta', $post->ID, $key ) ) {
         continue;
         }
         echo "\n<option value='" . esc_attr( $key ) . "'>" . esc_html(
 $index ) . '</option>';
 }
 }}}


 also i know should be change codes when get submitted metadata and i dont
 any idea for it.
 tnx a lot

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/54343>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list