fix: hide empty show metadata

This commit is contained in:
bisco
2026-06-25 17:50:53 +02:00
parent f49026b317
commit 9c5a51745f
5 changed files with 17 additions and 4 deletions
+6 -1
View File
@@ -56,6 +56,7 @@ add_action( 'add_meta_boxes', 'azionelab_add_meta_boxes' );
function azionelab_show_meta_box( WP_Post $post ): void {
wp_nonce_field( 'azionelab_save_meta', 'azionelab_meta_nonce' );
$year = get_post_meta( $post->ID, 'azl_show_year', true );
$year = '0' === (string) $year ? '' : $year;
$location = get_post_meta( $post->ID, 'azl_show_location', true );
?>
<p>
@@ -96,7 +97,11 @@ function azionelab_save_meta( int $post_id ): void {
$post_type = get_post_type( $post_id );
if ( 'azl_show' === $post_type ) {
$excerpt = isset( $_POST['azl_show_excerpt'] ) ? sanitize_textarea_field( wp_unslash( $_POST['azl_show_excerpt'] ) ) : '';
$year = isset( $_POST['azl_show_year'] ) ? absint( $_POST['azl_show_year'] ) : 0;
$year = '';
if ( isset( $_POST['azl_show_year'] ) && '' !== trim( (string) wp_unslash( $_POST['azl_show_year'] ) ) ) {
$submitted_year = absint( $_POST['azl_show_year'] );
$year = $submitted_year >= 1900 && $submitted_year <= 2100 ? (string) $submitted_year : '';
}
$location = isset( $_POST['azl_show_location'] ) ? sanitize_text_field( wp_unslash( $_POST['azl_show_location'] ) ) : '';
update_post_meta( $post_id, 'azl_show_year', $year );
update_post_meta( $post_id, 'azl_show_location', $location );