AnsPress_Tag::ask_from_tag_field( array $args, boolean $editing )

Description #

Add tag field in ask form.

Parameters #

  • $args
    array (Required) Arguments.
  • $editing
    boolean (Required) Is editing form.

Source #

File: addons/free/tag.php

	public static function ask_from_tag_field( $args, $editing ) {
		global $editing_post;
		$tag_val = $editing ? get_the_terms( $editing_post->ID, 'question_tag' ) : ap_sanitize_unslash( 'tags', 'r', [] ) ;

		ob_start();
		?>
			<div class="ap-field-tags ap-form-fields">
				<label class="ap-form-label" for="tags"><?php esc_attr_e( 'Tags', 'anspress-question-answer' ); ?></label>
				<div data-role="ap-tagsinput" class="ap-tags-input">
					<div id="ap-tags-add">
						<input id="tags" class="ap-tags-field ap-form-control" placeholder="<?php esc_attr_e( 'Type and hit enter', 'anspress-question-answer' ); ?>" autocomplete="off" />
						<ul id="ap-tags-suggestion">
						</ul>
					</div>

					<ul id="ap-tags-holder" aria-describedby="ap-tags-list-title">
						<?php foreach ( (array) $tag_val as $tag ) { ?>
							<?php if ( ! empty( $tag->slug ) ) { ?>
								<li class="ap-tagssugg-item">
									<button role="button" class="ap-tag-remove"><span class="sr-only"></span> <span class="ap-tag-item-value"><?php echo esc_attr( $tag->slug ); ?></span><i class="apicon-x"></i></button>
									<input type="hidden" name="tags[]" value="<?php echo esc_attr( $tag->slug ); ?>" />
								</li>
							<?php } ?>
						<?php } ?>
					</ul>
				</div>
			</div>
		<?php

		$tag_field = ob_get_clean();
		$args['fields'][] = array(
			'name' 		=> 'tag',
			'label' 	=> __( 'Tags', 'anspress-question-answer' ),
			'type'  	=> 'custom',
			'taxonomy' 	=> 'question_tag',
			'desc' 		=> __( 'Slowly type for suggestions', 'anspress-question-answer' ),
			'order' 	=> 11,
			'html' 		=> $tag_field,
		);

		return $args;
	}

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