Skip to content

Commit

Permalink
Bug:Quesions are not random if category limits are set.
Browse files Browse the repository at this point in the history
  • Loading branch information
krunalexpresstech committed Oct 2, 2023
1 parent e47a5eb commit 094c890
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion php/classes/class-qmn-quiz-manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -683,7 +683,11 @@ public function load_questions( $quiz_id, $quiz_options, $is_quiz_page, $questio
if ( ! empty( $tq_ids ) && ! empty( (array_column(array_merge(...array_map('array_merge', $tq_ids)),'question_id')) ) ) {
$exclude_ids = implode(',', array_column(array_merge(...array_map('array_merge', $tq_ids)),'question_id') );
}
$tq_ids[] = $wpdb->get_results( "SELECT DISTINCT `question_id` FROM `{$wpdb->prefix}mlw_question_terms` WHERE `quiz_id` = $quiz_id AND `term_id` = $category AND `taxonomy`='qsm_category' AND question_id NOT IN ($exclude_ids) LIMIT $limit", ARRAY_A );
$category_order_sql = '';
if ( 1 == $quiz_options->randomness_order || 2 == $quiz_options->randomness_order ) {
$category_order_sql = 'ORDER BY rand()';
}
$tq_ids[] = $wpdb->get_results( "SELECT DISTINCT `question_id` FROM `{$wpdb->prefix}mlw_question_terms` WHERE `quiz_id` = $quiz_id AND `term_id` = $category AND `taxonomy`='qsm_category' AND question_id NOT IN ($exclude_ids) ".esc_sql( $category_order_sql )." LIMIT $limit", ARRAY_A );
}
$final_result = array_column(array_merge(...array_map('array_merge', $tq_ids)),'question_id');
if ( 1 == $quiz_options->randomness_order || 2 == $quiz_options->randomness_order ) {
Expand Down

0 comments on commit 094c890

Please sign in to comment.