ff50cbdff8
・バグ修正:カスタムフィールドのselected属性の追加漏れ修正
31 lines
1.0 KiB
PHP
31 lines
1.0 KiB
PHP
<?php
|
|
|
|
if ( ! defined( 'ABSPATH' ) ) {
|
|
exit;
|
|
} // Exit if accessed directly
|
|
if ( ! trait_exists( 'CUSTOMFIELD_SELECT' ) ) {
|
|
|
|
trait CUSTOMFIELD_SELECT {
|
|
|
|
public static function set_all_customfield_select( $name_meta_key, $meta_key ) {
|
|
$selects = self::get_all_custom_fields();
|
|
echo '<select class="custom_field_key_select" name="' . esc_attr( $name_meta_key ) . '" required>';
|
|
foreach ( $selects as $select ) {
|
|
if ( $select->meta_key == $meta_key ) {
|
|
$selected = ' selected';
|
|
} else {
|
|
$selected = '';
|
|
}
|
|
echo '<option value="' . esc_attr( $select->meta_key ) . '"' . esc_attr( $selected ) . '>' . esc_html( $select->meta_key ) . '</option>';
|
|
}
|
|
echo '</select>';
|
|
}
|
|
|
|
private static function get_all_custom_fields() {
|
|
global $wpdb;
|
|
|
|
//アンダーバーで始まるシステム系のパラメータは除外する
|
|
return $wpdb->get_results( 'SELECT DISTINCT meta_key FROM ' . $wpdb->prefix . 'postmeta WHERE meta_key NOT LIKE ' . "'\_%' ORDER BY meta_key ASC" );
|
|
}
|
|
}
|
|
} |