Make WordPress Core

Opened 3 months ago

#54343 new feature request

set custom name for metadata value in custom-fileds metabox select box

Reported by: myousefi08 Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 5.8.1
Component: General Keywords:
Focuses: Cc:

Description

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

Change History (0)

Note: See TracTickets for help on using tickets.