LLMS_Question::get_choices( string $return = 'choices' )
Retrieve the question’s choices
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'
Return Return
(array)
Source Source
File: includes/models/model.llms.question.php
public function get_choices( $return = 'choices' ) {
global $wpdb;
$results = $wpdb->get_results( // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery
$wpdb->prepare(
"SELECT meta_key AS id
, meta_value AS data
FROM {$wpdb->postmeta}
WHERE post_id = %d
AND meta_key LIKE %s
;",
$this->get( 'id' ),
'_llms_choice_%'
)
);
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, array( 'allowed_classes' => false ) ) ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.serialize_unserialize
}
return $ret;
}
Expand full source code Collapse full source code View on GitHub
Changelog Changelog
| Version | Description |
|---|---|
| 4.4.0 | Don't allow objects when using unserialize(). |
| 3.35.0 | Escape LIKE clause. |
| 3.30.1 | Improve choice sorting to accommodate numeric markers. |
| 3.16.0 | Introduced. |