LLMS_Question::get_choices( string $return = 'choices' )

Retrieve the question’s choices


Description Description


Parameters Parameters

$return

(string) (Optional) Determine how to return the choice data. 'choices' (default) returns an array of LLMS_Question_Choice objects. 'ids' returns an array of LLMS_Question_Choice ids.

Default value: 'choices'


Top ↑

Return Return

(array)


Top ↑

Source Source

File: includes/models/model.llms.question.php

	public function get_choices( $return = 'choices' ) {

		global $wpdb;
		$results = $wpdb->get_results( $wpdb->prepare(
			"SELECT meta_key AS id
				  , meta_value AS data
			 FROM {$wpdb->postmeta}
			 WHERE post_id = %d
			   AND meta_key LIKE '_llms_choice_%'
			;", $this->get( 'id' )
		) );

		usort( $results, array( $this, 'sort_choices' ) );

		if ( 'ids' === $return ) {
			return wp_list_pluck( $results, 'id' );
		}

		$ret = array();
		foreach ( $results as $result ) {
			$ret[] = new LLMS_Question_Choice( $this->get( 'id' ), unserialize( $result->data ) );
		}

		return $ret;

	}

Top ↑

Changelog Changelog

Changelog
Version Description
3.30.1 Improve choice sorting to accommodate numeric markers.
3.16.0 Introduced.


Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.





Permalink: