Tags::get_options()

Description #

Return options of a tags field.

Changelog #

VersionDescription
4.1.8Introduced.

Source #

File: lib/form/class-tags.php

	private function get_options() {
		$options = $this->get( 'options' );

		if ( is_string( $options ) && 'terms' === $options ) {
			$options = array();
			if ( ! empty( $this->value() ) ) {
				$value    = $this->value();
				$tax_args = array(
					'taxonomy'   => $this->get( 'terms_args.taxonomy' ),
					'hide_empty' => false,
					'count'      => true,
					'number'     => 20,
				);

				if ( ! empty( $value ) ) {
					$tax_args['include'] = $value;
				}

				$terms = get_terms( $tax_args );

				if ( $terms ) {
					foreach ( $terms as $tag ) {
						$options[] = array(
							'term_id'     => $tag->term_id,
							'name'        => $tag->name,
							'description' => $tag->description,
							'count'       => $tag->count,
						);
					}
				}
			}

			return $options;
		} elseif ( is_string( $options ) && 'posts' === $options ) {
			return wp_list_pluck( get_posts( $this->get( 'posts_args', array() ) ), 'post_title', 'ID' );
		}

		return array();
	}

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Add your comment