Files
POST_ORDER_BY_ARCHIVE/util/apop-customfield-select.php
T
nobu ff50cbdff8 WP PLUGIN
・バグ修正:カスタムフィールドのselected属性の追加漏れ修正
2021-06-26 03:09:28 +09:00

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" );
}
}
}