LLMS_AJAX::query_quiz_questions()
Retrieve Quiz Questions
Description Description
Used by Select2 AJAX functions to load paginated quiz questions Also allows querying by question title
Return Return
(void)
Source Source
File: includes/class.llms.ajax.php
* @return void
*/
public function query_quiz_questions() {
// Grab the search term if it exists.
$term = array_key_exists( 'term', $_REQUEST ) ? llms_filter_input_sanitize_string( INPUT_POST, 'term' ) : '';
$page = array_key_exists( 'page', $_REQUEST ) ? llms_filter_input( INPUT_POST, 'page', FILTER_SANITIZE_NUMBER_INT ) : 0;
global $wpdb;
$limit = 30;
$start = $limit * $page;
if ( $term ) {
$like = " AND post_title LIKE '%s'";
$vars = array( '%' . $term . '%', $start, $limit );
} else {
$like = '';
$vars = array( $start, $limit );
}
// phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared
$questions = $wpdb->get_results(
$wpdb->prepare(
"SELECT ID, post_title
FROM $wpdb->posts
WHERE
post_type = 'llms_question'
AND post_status = 'publish'
$like
ORDER BY post_title
LIMIT %d, %d
",
$vars
)
);
// phpcs:enable WordPress.DB.PreparedSQL.InterpolatedNotPrepared
$r = array();
foreach ( $questions as $q ) {
$r[] = array(
'id' => $q->ID,
'name' => $q->post_title . ' (' . $q->ID . ')',
);
}
echo json_encode(
array(
'items' => $r,
'more' => count( $r ) === $limit,
'success' => true,
)
);
wp_die();
Expand full source code Collapse full source code View on GitHub
Changelog Changelog
| Version | Description |
|---|---|
| 5.9.0 | Introduced. |