AnsPress_Category::ask_from_category_field( array $args, boolean $editing )

Description #

Add category field in ask form.

Parameters #

  • $args
    array (Required) Ask form arguments.
  • $editing
    boolean (Required) true if is edit form.

Changelog #

VersionDescription
2.0Introduced.

Source #

File: addons/free/category.php

	public static function ask_from_category_field( $args, $editing ) {
		if ( wp_count_terms( 'question_category' ) == 0 ) { // WPCS: loose comparison okay.
			return $args;
		}

		global $editing_post;

		$catgeory = ap_sanitize_unslash( 'category', 'request' );

		if ( $editing ) {
			$category = get_the_terms( $editing_post->ID, 'question_category' );
			$catgeory = $category[0]->term_id;
		}

		$args['fields'][] = array(
			'name' 		    => 'category',
			'label' 	    => __( 'Category', 'anspress-question-answer' ),
			'type'  	    => 'taxonomy_select',
			'value' 	    => ( ! empty( $catgeory ) ? $catgeory: '' ),
			'taxonomy' 	  => 'question_category',
			'orderby' 	  => ap_opt( 'form_category_orderby' ),
			'desc' 		    => __( 'Select a topic that best fits your question', 'anspress-question-answer' ),
			'order' 	    => 6,
			'sanitize'    => [ 'only_int' ],
			'validate'    => [ 'required' ],
		);

		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