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 );
+3 -1
View File
@@ -119,11 +119,13 @@ $features = array(
$fallback = azionelab_asset( 0 === $show_index % 2 ? 'show-one.svg' : 'show-two.svg' );
$image = get_the_post_thumbnail_url( get_the_ID(), 'large' ) ?: $fallback;
$year = get_post_meta( get_the_ID(), 'azl_show_year', true );
$year = '0' === (string) $year ? '' : $year;
$location = get_post_meta( get_the_ID(), 'azl_show_location', true );
$show_meta = implode( ' · ', array_filter( array( $year, $location ) ) );
?>
<article class="show-card">
<img src="<?php echo esc_url( $image ); ?>" alt="Locandina di <?php the_title_attribute(); ?>" width="700" height="880" loading="lazy">
<div class="show-copy"><p class="show-meta"><?php echo esc_html( trim( $year . ' · ' . $location, ' ·' ) ); ?></p><h3><?php the_title(); ?></h3><div><?php the_excerpt(); ?></div></div>
<div class="show-copy"><?php if ( $show_meta ) : ?><p class="show-meta"><?php echo esc_html( $show_meta ); ?></p><?php endif; ?><h3><?php the_title(); ?></h3><div><?php the_excerpt(); ?></div></div>
</article>
<?php
++$show_index;