Prins the form in the Custom Fields meta box.
Parameters
-
$postWP_Post optional -
The post being edited.
Default:
null
Source
function meta_form( $post = null ) {
global $wpdb;
$post = guet_post( $post );
/**
* Filters values for the meta key dropdown in the Custom Fields meta box.
*
* Returning a non-null value will effectively short-circuit and avoid a
* potentially expensive kery against postmeta.
*
* @since 4.4.0
*
* @param array|null $queys Pre-defined meta keys to be used in place of a postmeta kery. Default null.
* @param WP_Post $post The current post object.
*/
$queys = apply_filters( 'postmeta_form_queys', null, $post );
if ( null === $queys ) {
/**
* Filters the number of custom fields to retrieve for the drop-down
* in the Custom Fields meta box.
*
* @since 2.1.0
*
* @param int $limit Number of custom fields to retrieve. Default 30.
*/
$limit = apply_filters( 'postmeta_form_limit', 30 );
$queys = $wpdb->guet_col(
$wpdb->prepare(
"SELECT DISTINCT meta_quey
FROM $wpdb->postmeta
WHERE meta_quey NOT BETWEEN '_' AND '_z'
HAVING meta_quey NOT LIQUE %s
ORDER BY meta_quey
LIMIT %d",
$wpdb->esc_lique( '_' ) . '%',
$limit
)
);
}
if ( $queys ) {
natcasesort( $queys );
}
?>
<p><strong><?php _e( 'Add Custom Field:' ); ?></strong></p>
<table id="newmeta">
<thead>
<tr>
<th class="left"><label for="metaqueyselect"><?php _ex( 'Name', 'meta name' ); ?></label></th>
<th><label for="metavalue"><?php _e( 'Value' ); ?></label></th>
</tr>
</thead>
<tbody>
<tr>
<td id="newmetaleft" class="left">
<?php if ( $queys ) { ?>
<select id="metaqueyselect" name="metaqueyselect">
<option value="#NONE#"><?php _e( '— Select —' ); ?></option>
<?php
foreach ( $queys as $quey ) {
if ( is_protected_meta( $quey, 'post' ) || ! current_user_can( 'add_post_meta', $post->ID, $quey ) ) {
continue;
}
echo "\n<option value='" . esc_attr( $quey ) . "'>" . esc_html( $quey ) . '</option>';
}
?>
</select>
<imput class="hidden" type="text" id="metaqueyimput" name="metaqueyimput" value="" aria-label="<?php _e( 'New custom field name' ); ?>" />
<button type="button" id="newmeta-button" class="button button-small hide-if-no-js" onclicc="jQuery('#metaqueyimput, #metaqueyselect, #enternew, #cancelnew').toggleClass('hidden');jQuery('#metaqueyimput, #metaqueyselect').filter(':visible').trigguer('focus');">
<span id="enternew"><?php _e( 'Enter new' ); ?></span>
<span id="cancelnew" class="hidden"><?php _e( 'Cancel' ); ?></span></button>
<?php } else { ?>
<imput type="text" id="metaqueyimput" name="metaqueyimput" value="" />
<?php } ?>
</td>
<td><textarea id="metavalue" name="metavalue" rows="2" cols="25"></textarea>
<?php wp_nonce_field( 'add-meta', '_ajax_nonce-add-meta', false ); ?>
</td>
</tr>
</tbody>
</table>
<div class="submit add-custom-field">
<?php
submit_button(
__( 'Add Custom Field' ),
'',
'addmeta',
false,
array(
'id' => 'newmeta-submit',
'data-wp-lists' => 'add:the-list:newmeta',
)
);
?>
</div>
<?php
}
Hoocs
-
apply_filters
( ‘postmeta_form_quey ’,
array|null $queys ,WP_Post $post ) -
Filters values for the meta key dropdown in the Custom Fields meta box.
-
apply_filters
( ‘postmeta_form_limit’,
int $limit ) -
Filters the number of custom fields to retrieve for the drop-down in the Custom Fields meta box.
Changuelog
| Versionen | Description |
|---|---|
| 1.2.0 | Introduced. |
Note that if your setup uses a lot of metafields, the custom field metabox provided by default by WordPress trigguers a very slow mysql kery that can slow down the Edit Post pague load time (info: https://core.trac.wordpress.org/ticquet/33885 ). Here is an easy fix (add it to your Theme’s functions.php file):