我在自定义帖子类型过滤器上创建了一个ajax过滤器,当我选择10-12个过滤器时,它可以正常工作,但是在admin-ajax.php文件挂起后,我不知道出了什么问题。
网站网址:http://mustafafazal.com/intranet/carrier-filter-tool/ 您可以在开发人员模式> chrome网络中查看此问题。
https://i.stack.imgur.com/J0Rso.png
https://i.stack.imgur.com/uzug8.png
function misha_filter_function(){
$nested_condition = array();
if (isset($_POST['state']) && !empty($_POST['state'])){
$nested_condition[] = array(
'relation' => 'AND',
array(
'key' => 'state',
'value' => $_POST['state'],
//'compare' => 'LIKE'
),
);
}
if (isset($_POST['age']) && !empty($_POST['age'])){
$nested_condition[] = array(
'relation' => 'AND',
array(
'key' => 'age_min',
'value' => $_POST['age'],
'type' => 'NUMERIC',
'compare' => '<='
),
array(
'key' => 'age_max',
'value' => $_POST['age'],
'type' => 'NUMERIC',
'compare' => '>='
)
);
}
if (isset($_POST['months']) && !empty($_POST['months'])){
$nested_condition[] = array(
'relation' => 'AND',
array(
'key' => 'months_of_exp_min',
'value' => $_POST['months'],
'type' => 'NUMERIC',
'compare' => '<='
),
array(
'key' => 'months_of_exp_max',
'value' => $_POST['months'],
'type' => 'NUMERIC',
'compare' => '>='
)
);
}
if (isset($_POST['driver_type']) && !empty($_POST['driver_type'])){
// Get the selected options
$valueFront1 = $_POST['driver_type'];
// echo print_r($valueFront); die();
// Build the meta query based on the selected options
$meta_query = array('relation' => 'AND');
foreach( $valueFront1 as $item1 ){
$nested_condition[] = array(
'key' => 'driver_type',
'value' => $item1,
//'compare' => 'LIKE',
);
}
}
if (isset($_POST['division_requested']) && !empty($_POST['division_requested'])){
// Get the selected options
$valueFront2 = $_POST['division_requested'];
// echo print_r($valueFront); die();
// Build the meta query based on the selected options
$meta_query = array('relation' => 'AND');
foreach( $valueFront2 as $item2 ){
$nested_condition[] = array(
'key' => 'division',
'value' => $item2,
//'compare' => 'LIKE',
);
}
}
if (isset($_POST['freight_type']) && !empty($_POST['freight_type'])){
// Get the selected options
$valueFront3 = $_POST['freight_type'];
// echo print_r($valueFront); die();
// Build the meta query based on the selected options
$meta_query = array('relation' => 'AND');
foreach( $valueFront3 as $item3 ){
$nested_condition[] = array(
'key' => 'freight_type',
'value' => $item3,
//'compare' => 'LIKE',
);
}
}
if (isset($_POST['home_time_requested']) && !empty($_POST['home_time_requested'])){
// Get the selected options
$valueFront4 = $_POST['home_time_requested'];
// echo print_r($valueFront); die();
// Build the meta query based on the selected options
$meta_query = array('relation' => 'AND');
foreach( $valueFront4 as $item4 ){
$nested_condition[] = array(
'key' => 'home_time',
'value' => $item4,
//'compare' => 'LIKE',
);
}
}
if (isset($_POST['additional_options']) && !empty($_POST['additional_options'])){
// Get the selected options
$valueFront5 = $_POST['additional_options'];
// echo print_r($valueFront); die();
// Build the meta query based on the selected options
$meta_query = array('relation' => 'AND');
foreach( $valueFront5 as $item5 ){
$nested_condition[] = array(
'key' => 'additional_options',
'value' => $item5,
//'compare' => 'LIKE',
);
}
}
if (isset($_POST['sign_on_bonus_requested']) && !empty($_POST['sign_on_bonus_requested'])){
$nested_condition[] = array(
'relation' => 'AND',
array(
'key' => 'sign_on_bonus',
'value' => $_POST['sign_on_bonus_requested']
//'compare' => 'LIKE'
)
);
}
if (isset($_POST['careless_years']) && !empty($_POST['careless_years'])){
$nested_condition[] = array(
'relation' => 'AND',
array(
'key' => 'careless_min',
'value' => $_POST['careless_years'],
'type' => 'NUMERIC',
'compare' => '<='
),
array(
'key' => 'careless_max',
'value' => $_POST['careless_years'],
'type' => 'NUMERIC',
'compare' => '>='
)
);
}
if (isset($_POST['reckless_years']) && !empty($_POST['reckless_years'])){
$nested_condition[] = array(
'relation' => 'AND',
array(
'key' => 'recklace_min',
'value' => $_POST['reckless_years'],
'type' => 'NUMERIC',
'compare' => '<='
),
array(
'key' => 'recklace_max',
'value' => $_POST['reckless_years'],
'type' => 'NUMERIC',
'compare' => '>='
)
);
}
if (isset($_POST['dui']) && !empty($_POST['dui'])){
$nested_condition[] = array(
'relation' => 'AND',
array(
'key' => 'dui_in_cmv',
'value' => $_POST['dui'],
//'compare' => 'LIKE'
)
);
}
if (isset($_POST['dui_years']) && !empty($_POST['dui_years'])){
$nested_condition[] = array(
'relation' => 'AND',
array(
'key' => 'dui_yrs_min',
'value' => $_POST['dui_years'],
'type' => 'NUMERIC',
'compare' => '<='
),
array(
'key' => 'dui_yrs_max',
'value' => $_POST['dui_years'],
'type' => 'NUMERIC',
'compare' => '>='
)
);
}
if (isset($_POST['moving_violations']) && !empty($_POST['moving_violations'])){
$nested_condition[] = array(
'relation' => 'AND',
array(
'key' => 'no_of_moving_violations',
'value' => $_POST['moving_violations'],
'type' => 'NUMERIC',
'compare' => '='
)
);
}
if (isset($_POST['dot_recordable']) && !empty($_POST['dot_recordable'])){
$nested_condition[] = array(
'relation' => 'AND',
array(
'key' => 'dot_recordable_min',
'value' => $_POST['dot_recordable'],
'type' => 'NUMERIC',
'compare' => '<='
),
array(
'key' => 'dot_recordable_max',
'value' => $_POST['dot_recordable'],
'type' => 'NUMERIC',
'compare' => '>='
)
);
}
if (isset($_POST['preventable']) && !empty($_POST['preventable'])){
$nested_condition[] = array(
'relation' => 'AND',
array(
'key' => 'preventable_min',
'value' => $_POST['preventable'],
'type' => 'NUMERIC',
'compare' => '<='
),
array(
'key' => 'preventable_max',
'value' => $_POST['preventable'],
'type' => 'NUMERIC',
'compare' => '>='
)
);
}
if (isset($_POST['job_years']) && !empty($_POST['job_years'])){
$nested_condition[] = array(
'relation' => 'AND',
array(
'key' => '#_of_jobs_min',
'value' => $_POST['job_years'],
'type' => 'NUMERIC',
'compare' => '<='
),
array(
'key' => '#_of_jobs_max',
'value' => $_POST['job_years'],
'type' => 'NUMERIC',
'compare' => '>='
)
);
}
if (isset($_POST['terminated']) && !empty($_POST['terminated'])){
$nested_condition[] = array(
'relation' => 'AND',
array(
'key' => 'terminated',
'value' => $_POST['terminated'],
//'compare' => 'LIKE'
)
);
}
if (isset($_POST['safety_reasons']) && !empty($_POST['safety_reasons'])){
$nested_condition[] = array(
'relation' => 'AND',
array(
'key' => 'safety_term',
'value' => $_POST['safety_reasons'],
//'compare' => 'LIKE'
)
);
}
if (isset($_POST['last_job']) && !empty($_POST['last_job'])){
$nested_condition[] = array(
'relation' => 'AND',
array(
'key' => 'last_job_term',
'value' => $_POST['last_job'],
//'compare' => 'LIKE'
)
);
}
if (isset($_POST['alcohol_test']) && !empty($_POST['alcohol_test'])){
$nested_condition[] = array(
'relation' => 'AND',
array(
'key' => 'failed_da_test',
'value' => $_POST['alcohol_test'],
//'compare' => 'LIKE'
)
);
}
if (isset($_POST['how_long']) && !empty($_POST['how_long'])){
$nested_condition[] = array(
'relation' => 'AND',
array(
'key' => 'failed_when_min',
'value' => $_POST['how_long'],
'type' => 'NUMERIC',
'compare' => '<='
),
array(
'key' => 'failed_when_max',
'value' => $_POST['how_long'],
'type' => 'NUMERIC',
'compare' => '>='
)
);
}
$args = array(
'post_type' => 'carrier',
'post_status' => 'publish',
'order' => 'ASC',
'posts_per_page' => -1,
'meta_query' => $nested_condition
);
// query
$the_query = new WP_Query( $args );
//echo $the_query->request; die();
?>
<?php
if ( $the_query->have_posts() ) :
while ( $the_query->have_posts() ) : $the_query->the_post();
?>
<div class="carrier-box">
<h2><?php the_title(); ?></h2>
<a class="read-more" href="<?php the_permalink(); ?>">Website</a>
</div>
<?php
endwhile;
endif;
?>
<?php
wp_reset_query(); // Restore global post data stomped by the_post(). ?>
<?php
die();
}
add_action('wp_ajax_myfilter', 'misha_filter_function');
add_action('wp_ajax_nopriv_myfilter', 'misha_filter_function');