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
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 | * @ 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. |