Search take much time and not show search results
-
want to make advance search page in wordpress and almost it working fine, but when I use all the fields (12 fields) to search a particular post then it take much time and also not appear the search page. sorry for long code.
here is php code….
global $wp_query; $query_vars = $wp_query->query_vars; $post_per_page = 12; global $term; $term = (strip_tags($_GET['term'])); if (!empty($_GET['term'])) { add_filter('posts_where', 'taskerdev_posts_where'); } $meta_query = array(); $closed = array( 'key' => 'closed', 'value' => "0", 'compare' => '=' ); $meta_query[] = $closed; if (!empty($_GET['tasker_cat_cat'])) $tasker_cat = array( 'taxonomy' => 'tasker_cat', 'field' => 'slug', 'terms' => $_GET['tasker_cat_cat']); else $tasker_cat = ''; $meta_query[] = $tasker_cat; if (!empty($_GET['vert_quality'])) { $tasker_cat_2 = array( 'relation' => 'OR', array( 'key' => 'custom_field_value_48', 'value' => $_GET['vert_quality'], 'compare' => '=' ), array( 'key' => 'custom_field_value_4', 'value' => $_GET['vert_quality'], 'compare' => '=' ) ); } else { $tasker_cat_2 = ''; } $meta_query[] = $tasker_cat_2; if (!empty($_GET['est_quantity'])) { $tasker_cat_3 = array( 'relation' => 'OR', array( 'key' => 'custom_field_value_69', 'value' => $_GET['est_quantity'], 'compare' => '=' ), array( 'key' => 'custom_field_value_27', 'value' => $_GET['est_quantity'], 'compare' => '=' ) ); } else { $tasker_cat_3 = ''; } $meta_query[] = $tasker_cat_3; if (!empty($_GET['comp_model'])) { $tasker_cat_4 = array( 'relation' => 'OR', array( 'key' => 'custom_field_value_28', 'value' => $_GET['comp_model'], 'compare' => '=' ), array( 'key' => 'custom_field_value_1', 'value' => $_GET['comp_model'], 'compare' => '=' ) ); } else { $tasker_cat_4 = ''; } $meta_query[] = $tasker_cat_4; if (!empty($_GET['delivery_type'])) { $tasker_cat_5 = array( 'relation' => 'OR', array( 'key' => 'custom_field_value_70', 'value' => $_GET['delivery_type'], 'compare' => '=' ), array( 'key' => 'custom_field_value_30', 'value' => $_GET['delivery_type'], 'compare' => '=' ) ); } else { $tasker_cat_5 = ''; } $meta_query[] = $tasker_cat_5; if (!empty($_GET['target_option'])) { $tasker_cat_6 = array( 'relation' => 'OR', array( 'key' => 'custom_field_value_29', 'value' => $_GET['target_option'], 'compare' => '=' ), array( 'key' => 'custom_field_value_67', 'value' => $_GET['target_option'], 'compare' => '=' ) ); } else { $tasker_cat_6 = ''; } $meta_query[] = $tasker_cat_6; if (!empty($_GET['tracking_method'])) { $tasker_cat_7 = array( 'relation' => 'OR', array( 'key' => 'custom_field_value_72', 'value' => $_GET['tracking_method'], 'compare' => '=' ), array( 'key' => 'custom_field_value_25', 'value' => $_GET['tracking_method'], 'compare' => '=' ) ); } else { $tasker_cat_7 = ''; } $meta_query[] = $tasker_cat_7; if (!empty($_GET['revenue_auditing'])) { $tasker_cat_8 = array( 'relation' => 'OR', array( 'key' => 'custom_field_value_26', 'value' => $_GET['revenue_auditing'], 'compare' => '=' ), array( 'key' => 'custom_field_value_66', 'value' => $_GET['revenue_auditing'], 'compare' => '=' ) ); } else { $tasker_cat_8 = ''; } $meta_query[] = $tasker_cat_8; if ($_GET['feature_listing'] == "1") { $tasker_cat_9 = array( 'relation' => 'OR', array( 'key' => 'featured', 'value' => "1", 'compare' => '=' ), array( 'key' => 'featured_paid', 'value' => "1", 'compare' => '=' ) ); } else { $tasker_cat_9 = ''; } $meta_query[] = $tasker_cat_9; if (!empty($_GET['post_tag_cat'])) { $tasker_tag = array( 'taxonomy' => 'post_tag', 'field' => 'slug', 'terms' => $_GET['post_tag_cat']); } else $tasker_tag = ''; $meta_query[] = $tasker_tag; if (!empty($_GET['tasker_location_cat'])) $tasker_location = array( 'key' => 'tasker_location_cat', 'value' => $_GET['tasker_location_cat'], 'compare' => '=' ); else $tasker_location = ''; $meta_query[] = $tasker_location; if (isset($_GET['pricemin']) || isset($_GET['pricemax'])) { if (!empty($_GET['pricemax'])) $max = $_GET['pricemax']; else $max = 99999999; if (!empty($_GET['pricemin'])) $min = $_GET['pricemin']; else $min = 0; $price_q = array( 'key' => 'price', 'value' => array($min, $max), 'type' => 'numeric', 'compare' => 'BETWEEN' ); $meta_query[] = $price_q; } $tp = array('task', 'service'); if (isset($_GET['post_type2']) and ! empty($_GET['post_type2'])) $tp = $_GET['post_type2']; $args = array('post_type' => $tp, 'order' => 'DESC', 'orderby' => 'date', 'posts_per_page' => $post_per_page, 'paged' => $query_vars['paged'], 'meta_query' => $meta_query, 'tax_query' => array($tasker_cat, $tasker_location, $tasker_tag)); print_r($args); die("end"); query_posts($args); if (have_posts()) : while (have_posts()) : the_post(); global $post; ?> <?php if ($view == "grid"): ?> <?php if ($post->post_type == "task"): TaskerDev_get_post_task_main_function_grid_new_design(); else: TaskerDev_get_post_service_main_function_grid_new_design(); endif; ?> <?php else: ?> <?php if ($post->post_type == "task"): TaskerDev_get_post_task_main_function_new_design(); else: TaskerDev_get_post_service_main_function_new_design(); endif; ?> <?php endif; ?> <?php endwhile; if (function_exists('wp_pagenavi')): wp_pagenavi(); endif; else: _e("There are no active Taste Requests/Taste Offer according your search.", 'TaskerDev'); endif; wp_reset_query(); ?>
- The topic ‘Search take much time and not show search results’ is closed to new replies.