Inventory_Presser_Taxonomies::taxonomy_meta_box_html( string $taxonomy_name, string $element_name, WP_Post $post )

Creates HTML output for a meta box that turns a taxonomy into a select drop-down list instead of the typical checkboxes. Including a blank option is the only way a user can remove the value.



(string) (Required)


(string) (Required)


(WP_Post) (Required) A post


(string) HTML that renders a editor meta box for a taxonomy


File: includes/class-taxonomies.php

	protected static function taxonomy_meta_box_html( $taxonomy_name, $element_name, $post ) {
		$html = sprintf(
			'<select name="%s" id="%s"><option></option>',

		// get all the term names and slugs for $taxonomy_name.
		$terms = get_terms( $taxonomy_name, array( 'hide_empty' => false ) );

		if ( ! empty( $terms ) && ! is_wp_error( $terms ) ) {
			// get the saved term for this taxonomy.
			$saved_term_slug = self::get_term_slug( $taxonomy_name, $post->ID );

			foreach ( $terms as $term ) {
				$html .= sprintf(
					'<option value="%s"%s>%s</option>',
					selected( strtolower( $term->slug ), strtolower( $saved_term_slug ), false ),
		return $html . '</select>';