Gamipress_Helpers::select_achievements_from_types_func()

Return all the specific fields of a form ID provided in ajax call


Source Source

File: src/integrations/gamipress/helpers/gamipress-helpers.php

	public function select_achievements_from_types_func() {



		// Nonce and post object validation
		Automator()->utilities->ajax_auth_check( $_POST );

		$fields = array();
		if ( isset( $_POST['value'] ) && ! empty( $_POST['value'] ) ) {

			$args = [
				'post_type'      => sanitize_text_field( $_POST['value'] ),
				'posts_per_page' => 999,
				'orderby'        => 'title',
				'order'          => 'ASC',
				'post_status'    => 'publish',
			];

			$options = Automator()->helpers->recipe->options->wp_query( $args, false, esc_attr__( 'Any awards', 'uncanny-automator' ) );

			foreach ( $options as $award_id => $award_name ) {
				$fields[] = [
					'value' => $award_id,
					'text'  => $award_name,
				];
			}
		}
		echo wp_json_encode( $fields );
		die();
	}