Components

	function qzr_page_target_meta_box( $post) {
		$qzr_targets = get_terms([
			'taxonomy' => 'qzr_target',
			'hide_empty' => false,
		]);

		$current_targets = get_the_terms($post->ID,'qzr_target');

		if(is_array($current_targets)) {
			$current_term_slug = count($current_targets) > 1? 'all' : $current_targets[0]->slug;
		}
		else {
			$current_term_slug = false;
		}
	?>
		<select name="qzr_target" class="qzr_target">
			<?= !$current_term_slug ? '<option selected disabled>Seleziona un target</option>' : '' ?>
			<?php foreach($qzr_targets as $target): ?>
				<option value="<?= $target->slug?>" <?= $target->slug == $current_term_slug? 'selected' : '' ?>>
				<?= $target->name?>
			</option>	
			<?php endforeach?>
		</select>
		<?php
	}

	function qzr_save_target_meta( $post_id ){
		if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE )
		return $post_id;
		if(isset($_POST['qzr_target'])) {
			if($_POST['qzr_target'] == 'all') {
				$qzr_targets = get_terms([
					'taxonomy' => 'qzr_target',
					'hide_empty' => false,
				]);
				$all_targets = [];

				foreach($qzr_targets as $target) {
					array_push($all_targets,$target->term_id);
				}
				wp_set_post_terms( $post_id, $all_targets, 'qzr_target' );	
			}
			else {
				$term = get_term_by( 'slug',$_POST['qzr_target'], 'qzr_target' );
				if($term->term_id > 0) {
					wp_set_post_terms( $post_id, array( $term->term_id ), 'qzr_target' );
				}
			}
		}
	}
	add_action( 'save_post', 'qzr_save_target_meta', 10, 2 );

	function qzr_post_target_meta() {
		add_meta_box( 'qzr_page_target', 'Target', 'qzr_page_target_meta_box','page','side','high' );
		add_meta_box( 'qzr_page_target', 'Target', 'qzr_page_target_meta_box','post','side','high' );
		add_meta_box( 'qzr_page_target', 'Target', 'qzr_page_target_meta_box','project','side','high' );
	}
	add_action( 'admin_init', 'qzr_post_target_meta' );

Similiar Collections

Python strftime reference pandas.Period.strftime python - Formatting Quarter time in pandas columns - Stack Overflow python - Pandas: Change day - Stack Overflow python - Check if multiple columns exist in a df - Stack Overflow Pandas DataFrame apply() - sending arguments examples python - How to filter a dataframe of dates by a particular month/day? - Stack Overflow python - replace a value in the entire pandas data frame - Stack Overflow python - Replacing blank values (white space) with NaN in pandas - Stack Overflow python - get list from pandas dataframe column - Stack Overflow python - How to drop rows of Pandas DataFrame whose value in a certain column is NaN - Stack Overflow python - How to drop rows of Pandas DataFrame whose value in a certain column is NaN - Stack Overflow python - How to lowercase a pandas dataframe string column if it has missing values? - Stack Overflow How to Convert Integers to Strings in Pandas DataFrame - Data to Fish How to Convert Integers to Strings in Pandas DataFrame - Data to Fish create a dictionary of two pandas Dataframe columns? - Stack Overflow python - ValueError: No axis named node2 for object type <class 'pandas.core.frame.DataFrame'> - Stack Overflow Python Pandas iterate over rows and access column names - Stack Overflow python - Creating dataframe from a dictionary where entries have different lengths - Stack Overflow python - Deleting DataFrame row in Pandas based on column value - Stack Overflow python - How to check if a column exists in Pandas - Stack Overflow python - Import pandas dataframe column as string not int - Stack Overflow