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

taxonomy_meta_box_html


Description Description

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.


Top ↑

Parameters Parameters

$taxonomy_name

(string) (Required)

$element_name

(string) (Required)

$post

(WP_Post) (Required) A post


Top ↑

Return Return

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


Top ↑

Source Source

File: includes/class-taxonomies.php

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

		//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>',
					$term->slug,
					selected( strtolower( $term->slug ), strtolower( $saved_term_slug ), false ),
					$term->name
				);
			}
		}
		return $HTML . '</select>';
	}