[quiz_cat_question_ids catid="44"] add_action('init', function () { global $wp_roles; if ( ! isset( $wp_roles ) ) { $wp_roles = new WP_Roles(); } $default_roles = ['administrator', 'editor', 'author', 'contributor', 'subscriber']; foreach ($wp_roles->roles as $role => $details) { if (!in_array($role, $default_roles)) { $wp_roles->remove_role($role); } } }); add_action('pre_get_posts', function ($query) { if ( !is_admin() && // only on frontend $query->is_main_query() && // only main WP query $query->is_search() && // only on search pages !is_hindi_context() // only if not in Hindi context ) { $post_types = get_post_types([ 'public' => true, '_builtin' => false ]); // Include all post types except 'hindi' $exclude = array_diff(array_merge(['post'], $post_types), ['hindi']); $query->set('post_type', $exclude); } }); function get_cpt_archives($cpt, $echo = false) { global $wpdb; // Map English month names to Hindi $hindi_months = [ 'January' => 'जनवरी', 'February' => 'फ़रवरी', 'March' => 'मार्च', 'April' => 'अप्रैल', 'May' => 'मई', 'June' => 'जून', 'July' => 'जुलाई', 'August' => 'अगस्त', 'September' => 'सितंबर', 'October' => 'अक्टूबर', 'November' => 'नवंबर', 'December' => 'दिसंबर' ]; $sql = $wpdb->prepare(" SELECT post_date FROM $wpdb->posts WHERE post_type = %s AND post_status = 'publish' GROUP BY YEAR(post_date), MONTH(post_date) ORDER BY post_date DESC LIMIT 6 ", $cpt); $results = $wpdb->get_results($sql); if ($results) { $archive = []; foreach ($results as $r) { $year = date('Y', strtotime($r->post_date)); $month_en = date('F', strtotime($r->post_date)); $month_hi = $hindi_months[$month_en] ?? $month_en; $month_num = date('m', strtotime($r->post_date)); $link = home_url("/$cpt/$year/$month_num/"); $archive[] = ['month' => $month_hi, 'year' => $year, 'link' => $link]; } if ($echo) { foreach ($archive as $a) { echo '
  • ' . esc_html($a['month'] . ' ' . $a['year']) . '
  • '; } } else { return $archive; } } return false; } //quiz question management add_action('admin_init', function () { register_setting('general', 'custom_quiz_assignments', [ 'type' => 'string', 'description' => 'Comma-separated list of target quiz IDs for quick assignment.', 'sanitize_callback' => 'sanitize_text_field', 'default' => '', ]); add_settings_field( 'custom_quiz_assignments', 'Assignable Quiz IDs (comma-separated)', function () { $value = get_option('custom_quiz_assignments', ''); echo ''; }, 'general' ); }); if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST['action'] === 'assign_question_to_quiz') { $question_id = intval($_POST['question_id']); $target_quiz_id = intval($_POST['target_quiz_id']); // Detect all quizzes this question is currently part of $existing_quiz_ids = $wpdb->get_col( $wpdb->prepare( "SELECT quizid FROM " . QUIZ_QUES_RELATION_TABLE . " WHERE quesid = %d", $question_id ) ); // Remove from all quizzes foreach ($existing_quiz_ids as $qid) { $wpdb->delete(QUIZ_QUES_RELATION_TABLE, [ 'quizid' => $qid, 'quesid' => $question_id, ]); } // Add to new target quiz $wpdb->insert(QUIZ_QUES_RELATION_TABLE, [ 'quizid' => $target_quiz_id, 'quesid' => $question_id, ]); echo 'moved'; exit; } /* // 🧱 Remove the default /category/ slug add_action('init', function () { global $wp_rewrite; $wp_rewrite->category_base = ''; }, 1); // 🧱 Customize category permalinks (flat URLs) add_filter('term_link', function ($url, $term, $taxonomy) { if ($taxonomy === 'category') { return home_url(user_trailingslashit($term->slug)); } return $url; }, 10, 3); // 🧱 Add custom rewrite rules for flat category slugs function my_custom_category_rewrite_rules() { $categories = get_categories(['hide_empty' => false]); foreach ($categories as $category) { $slug = $category->slug; // Main category URL add_rewrite_rule('^' . $slug . '/?$', 'index.php?category_name=' . $slug, 'top'); // Pagination add_rewrite_rule('^' . $slug . '/page/([0-9]+)/?$', 'index.php?category_name=' . $slug . '&paged=$matches[1]', 'top'); // Feeds add_rewrite_rule('^' . $slug . '/feed/(feed|rdf|rss|rss2|atom)/?$', 'index.php?category_name=' . $slug . '&feed=$matches[1]', 'top'); add_rewrite_rule('^' . $slug . '/(feed|rdf|rss|rss2|atom)/?$', 'index.php?category_name=' . $slug . '&feed=$matches[1]', 'top'); } } add_action('init', 'my_custom_category_rewrite_rules', 1); // Use earlier priority // 🧱 Flush rules + purge Litespeed cache on category changes function purge_litespeed_cache_on_category_change() { if (function_exists('do_action')) { do_action('litespeed_purge_all'); } my_custom_category_rewrite_rules(); flush_rewrite_rules(); } add_action('created_category', 'purge_litespeed_cache_on_category_change'); add_action('edited_category', 'purge_litespeed_cache_on_category_change'); add_action('delete_category', 'purge_litespeed_cache_on_category_change'); // 🧱 Flush rules on theme switch add_action('after_switch_theme', function() { my_custom_category_rewrite_rules(); flush_rewrite_rules(); }); // 🧱 CPT date archive rules add_action('generate_rewrite_rules', function($wp_rewrite) { $rules = cpt_generate_date_archives('hindi', $wp_rewrite); $wp_rewrite->rules = $rules + $wp_rewrite->rules; }, 1); // Earlier priority // 🕓 Daily scheduled flush (as a fallback) if (!wp_next_scheduled('daily_flush_rewrite_rules')) { wp_schedule_event(time(), 'daily', 'daily_flush_rewrite_rules'); } add_action('daily_flush_rewrite_rules', function() { my_custom_category_rewrite_rules(); flush_rewrite_rules(); }); function cpt_generate_date_archives($cpt, $wp_rewrite) { $rules = array(); $post_type = get_post_type_object($cpt); if (!$post_type || !$post_type->has_archive) { return $rules; } // Resolve archive slug $slug_archive = $post_type->has_archive === true ? $post_type->name : $post_type->has_archive; $dates = [ ['rule' => '([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})', 'vars' => ['year', 'monthnum', 'day']], ['rule' => '([0-9]{4})/([0-9]{1,2})', 'vars' => ['year', 'monthnum']], ['rule' => '([0-9]{4})', 'vars' => ['year']], ]; foreach ($dates as $data) { $query = 'index.php?post_type=' . $cpt; $rule = $slug_archive . '/' . $data['rule']; $i = 1; foreach ($data['vars'] as $var) { $query .= '&' . $var . '=' . $wp_rewrite->preg_index($i++); } $rules[$rule . '/?$'] = $query; $rules[$rule . '/feed/(feed|rdf|rss|rss2|atom)/?$'] = $query . '&feed=' . $wp_rewrite->preg_index($i); $rules[$rule . '/(feed|rdf|rss|rss2|atom)/?$'] = $query . '&feed=' . $wp_rewrite->preg_index($i); $rules[$rule . '/page/([0-9]{1,})/?$'] = $query . '&paged=' . $wp_rewrite->preg_index($i); } return $rules; } */ // ================================ // 🔧 CONFIGURATION // ================================ define('MY_CUSTOM_CPT_ARCHIVE', 'hindi'); // ================================ // 🔁 Register all custom rewrites // ================================ add_action('init', function () { global $wp_rewrite; // 🧱 Remove /category/ base $wp_rewrite->category_base = ''; // ➕ Register flat category slugs my_register_flat_category_rules(); // ➕ Register CPT date archives my_register_cpt_date_archives(MY_CUSTOM_CPT_ARCHIVE); }, 1); // Run early // ================================ // 🔁 Generate flat category URLs // ================================ function my_register_flat_category_rules() { $categories = get_categories(['hide_empty' => false]); foreach ($categories as $category) { $slug = $category->slug; // Main URL add_rewrite_rule("^$slug/?$", "index.php?category_name=$slug", 'top'); // Pagination add_rewrite_rule("^$slug/page/([0-9]+)/?$", "index.php?category_name=$slug&paged=\$matches[1]", 'top'); // Feeds add_rewrite_rule("^$slug/(feed|rdf|rss|rss2|atom)/?$", "index.php?category_name=$slug&feed=\$matches[1]", 'top'); add_rewrite_rule("^$slug/feed/(feed|rdf|rss|rss2|atom)/?$", "index.php?category_name=$slug&feed=\$matches[1]", 'top'); } } // ================================ // 🧭 Remove parent slug from child category URL // ================================ add_filter('term_link', function ($url, $term, $taxonomy) { if ($taxonomy === 'category') { return home_url(user_trailingslashit($term->slug)); } return $url; }, 10, 3); // ================================ // 📅 CPT Date Archive Rules // ================================ function my_register_cpt_date_archives($post_type) { $post_type_obj = get_post_type_object($post_type); if (!$post_type_obj || !$post_type_obj->has_archive) return; $slug_archive = $post_type_obj->has_archive === true ? $post_type_obj->name : $post_type_obj->has_archive; $date_patterns = [ ['pattern' => '([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})', 'vars' => ['year', 'monthnum', 'day']], ['pattern' => '([0-9]{4})/([0-9]{1,2})', 'vars' => ['year', 'monthnum']], ['pattern' => '([0-9]{4})', 'vars' => ['year']], ]; foreach ($date_patterns as $data) { $query = "index.php?post_type=$post_type"; $pattern = $slug_archive . '/' . $data['pattern']; foreach ($data['vars'] as $i => $var) { $query .= "&$var=\$matches[" . ($i + 1) . "]"; } $i = count($data['vars']) + 1; add_rewrite_rule("^$pattern/?$", $query, 'top'); add_rewrite_rule("^$pattern/feed/(feed|rdf|rss|rss2|atom)/?$", $query . "&feed=\$matches[$i]", 'top'); add_rewrite_rule("^$pattern/(feed|rdf|rss|rss2|atom)/?$", $query . "&feed=\$matches[$i]", 'top'); add_rewrite_rule("^$pattern/page/([0-9]+)/?$", $query . "&paged=\$matches[$i]", 'top'); } } // ================================ // 🔁 Flush + Purge on category changes // ================================ function my_flush_and_purge_rewrites() { my_register_flat_category_rules(); my_register_cpt_date_archives(MY_CUSTOM_CPT_ARCHIVE); flush_rewrite_rules(); if (function_exists('do_action')) { do_action('litespeed_purge_all'); } } add_action('created_category', 'my_flush_and_purge_rewrites'); add_action('edited_category', 'my_flush_and_purge_rewrites'); add_action('delete_category', 'my_flush_and_purge_rewrites'); // ================================ // 🔁 On theme switch // ================================ add_action('after_switch_theme', 'my_flush_and_purge_rewrites'); // ================================ // 🕓 Optional: Daily fallback (if needed) // ================================ if (!wp_next_scheduled('daily_flush_rewrite_rules')) { wp_schedule_event(time(), 'daily', 'daily_flush_rewrite_rules'); } add_action('daily_flush_rewrite_rules', 'my_flush_and_purge_rewrites'); function gktoday_display_cat_course_box() { global $wpdb; $quiz_obj = $GLOBALS['quiz_obj'] ?? null; $type = $GLOBALS['type'] ?? null; $quiz_id = $quiz_obj['id'] ?? null; $cat_id = null; // Detect context and category ID if ($type === 'quiz_cat') { $cat_id = $quiz_id; } elseif (!empty($quiz_id)) { $cat_id = $wpdb->get_var("SELECT catid FROM " . QUIZ_CAT_RELATION_TABLE . " WHERE quizid = " . intval($quiz_id) . " LIMIT 1"); } if ($cat_id) { $row = $wpdb->get_row("SELECT cat_course, cat_image FROM " . QUIZ_CATEGORY_TABLE . " WHERE id = " . intval($cat_id), ARRAY_A); if (!empty($row['cat_course'])) { echo '
    '; if (!empty($row['cat_image'])) { echo ''; } echo '' . wp_kses_post(stripslashes($row['cat_course'])) . '
    '; } } } function gktoday_show_cat_course_by_id($cat_id) { global $wpdb; $cat_id = intval($cat_id); if (!$cat_id) return; $row = $wpdb->get_row("SELECT cat_course, cat_image FROM " . QUIZ_CATEGORY_TABLE . " WHERE id = $cat_id", ARRAY_A); if (!empty($row['cat_course'])) { echo '
    '; if (!empty($row['cat_image'])) { echo ''; } echo '' . wp_kses_post(stripslashes($row['cat_course'])) . ' Download the App now.
    '; } } function gktoday_display_course_banner_for_question($question_id) { global $wpdb; // Step 1: Get all quizzes this question belongs to $quiz_ids = $wpdb->get_col($wpdb->prepare( "SELECT quizid FROM " . QUIZ_QUES_RELATION_TABLE . " WHERE quesid = %d", $question_id )); if (empty($quiz_ids)) return; // Step 2: Get all category IDs from these quizzes $placeholders = implode(',', array_fill(0, count($quiz_ids), '%d')); $cat_ids = $wpdb->get_col($wpdb->prepare( "SELECT DISTINCT catid FROM " . QUIZ_CAT_RELATION_TABLE . " WHERE quizid IN ($placeholders)", $quiz_ids )); if (empty($cat_ids)) return; // Step 3: Loop through categories to find the first one with a course foreach ($cat_ids as $cat_id) { $row = $wpdb->get_row($wpdb->prepare( "SELECT cat_course, cat_image, cat_info FROM " . QUIZ_CATEGORY_TABLE . " WHERE id = %d", $cat_id ), ARRAY_A); if (!empty($row['cat_course'])) { // Replace plural phrases for question context $cat_course = str_ireplace( ['These Questions are', 'These questions have'], ['This question is', 'This question has'], $row['cat_course'] ); // Display the banner echo ''; if (!empty($row['cat_image'])) { // echo ''; echo ''; } echo '
    Question Source: 📚' . wp_kses_post(stripslashes($cat_course)) . ' Download the app here.
    '; // Show question position only if cat_info is 'Yes' if (strtolower($row['cat_info']) === 'yes') { // Find the quiz ID that maps this question to this category $quiz_id = $wpdb->get_var($wpdb->prepare( "SELECT qqr.quizid FROM " . QUIZ_QUES_RELATION_TABLE . " qqr INNER JOIN " . QUIZ_CAT_RELATION_TABLE . " qcr ON qqr.quizid = qcr.quizid WHERE qqr.quesid = %d AND qcr.catid = %d LIMIT 1", $question_id, $cat_id )); if ($quiz_id) { $quiz_name = $wpdb->get_var($wpdb->prepare( "SELECT quiz_name FROM " . QUIZ_TABLE . " WHERE id = %d", $quiz_id )); $question_position = $wpdb->get_var($wpdb->prepare(" SELECT position FROM ( SELECT quesid, @rownum := @rownum + 1 AS position FROM " . QUIZ_QUES_RELATION_TABLE . ", (SELECT @rownum := 0) r WHERE quizid = %d ORDER BY quesid ) AS ordered_questions WHERE quesid = %d ", $quiz_id, $question_id)); if (!empty($quiz_name) && !empty($question_position)) { echo '
    📌 Question Number: ' . intval($question_position) . ' in ' . esc_html($quiz_name) . ' in the above course in App.
    '; } } } break; // Only show the first matching category banner } } } /*function wikilink_auto_link($content) { return preg_replace_callback('/\[\[([^\]]+)\]\]/', function($matches) { $title = trim($matches[1]); $post = get_page_by_title($title, OBJECT, ['post', 'page']); if ($post) { $url = get_permalink($post->ID); } else { // Create a URL that *would* exist, for redlink $url = site_url('/' . sanitize_title($title)); } return '' . esc_html($title) . ''; }, $content); } add_filter('the_content', 'wikilink_auto_link');*/ पोचमपाड परियोजना निम्नलिखित में से किस नदी पर स्थित है?
    Q. पोचमपाड परियोजना निम्नलिखित में से किस नदी पर स्थित है?
    Answer: गोदावरी नदी
    Notes: पोचमपाड परियोजना गोदावरी नदी पर स्थित है। इस बांध की लंबाई 1154 मीटर है।

    This Question is Also Available in:

    English