Какой хук срабатывает при выводе записей в post_type
Зарегистрировал post_type с полями custom-fields, добавил новую запись c полями Имя и Дата, нужно что бы в дальнейшем они выводились в такой последовательности (по id записи) при редактирование а они выводятся по алфавиту.
Хук pre_get_posts не срабатывает.
Поля (имя, дата) создаются автоматически.
add_action( 'init', 'register_post_types' );
function register_post_types() {
register_post_type( 'barthday', [
'labels' => [
'name' => 'Barthday',
'singular_name' => 'Barthday',
'add_new' => 'Добавить дату',
'add_new_item' => 'Добавление даты',
'edit_item' => 'Редактировать дату',
'new_item' => 'Новая дата',
'view_item' => 'Смотреть дату',
'search_items' => 'Искать дату',
'not_found' => 'Не найдено',
'not_found_in_trash' => 'Не найдено в корзине',
'menu_name' => 'Barthday',
],
'public' => false,
'show_ui' => true,
'supports' => array( 'title', 'custom-fields' )
] );
}
add_action( 'wp_insert_post', 'set_default_fields' );
function set_default_fields( $post_ID ) {
if( !chek_id_post_to_post_type_barthday( $post_ID ) ) return;
foreach( [ 'Имя', 'Дата' ] as $field ) {
$current_field_value = get_post_meta( $post_ID, $field, true );
$default_value = '';
if ( $current_field_value == '' && !wp_is_post_revision( $post_ID ) ) {
add_post_meta( $post_ID, $field, $default_value, true );
}
}
return $post_ID;
}
function chek_id_post_to_post_type_barthday( $id ) {
$get_screen = get_current_screen();
return ( $get_screen->id === 'barthday' ) ? true : false;
}