我有一个search form
具有wp_query
争论有很多checkbox
在此表单中
问题从这里开始,当您select all
对于选项,此查询几乎需要一分钟才能完成。以前有人有过这个问题吗?
我在HTML中使用了这些代码
<form action="<?php echo site_url() ?>/wp-admin/admin-ajax.php" method="POST" id="filter">
<label> <input type="checkbox" name="real_time_antivirus" /> Real-time Antivirus </label></br>
.
.
.
<label> <input type="checkbox" name="adware_prevention" /> adware_prevention </label></br>
<button>Apply filter</button>
<input type="hidden" name="action" value="myfilter">
在函数中。php
add_action(\'wp_ajax_myfilter\', \'misha_filter_function\'); // wp_ajax_{ACTION HERE}
add_action(\'wp_ajax_nopriv_myfilter\', \'misha_filter_function\');
function misha_filter_function(){
$args = array(
\'posts_per_page\' =>-1,
);
$args[\'meta_query\'] = array( \'relation\'=>\'AND\' );
// Antivirus_featured_scaning
if( isset( $_POST[\'real_time_antivirus\'] ) && $_POST[\'real_time_antivirus\'] == \'on\' )
$args[\'meta_query\'][] = array(
\'key\' => \'antivirus_antivirus_featured_scaning\',
\'value\' => \'real_time_antivirus\',
\'compare\' => \'LIKE\'
);
if( isset( $_POST[\'manual_virus_scanning\'] ) && $_POST[\'manual_virus_scanning\'] == \'on\' )
$args[\'meta_query\'][] = array(
\'key\' => \'antivirus_antivirus_featured_scaning\',
\'value\' => \'manual_virus_scanning\',
\'compare\' => \'LIKE\'
);
if( isset( $_POST[\'usb_virus_scan\'] ) && $_POST[\'usb_virus_scan\'] == \'on\' )
$args[\'meta_query\'][] = array(
\'key\' => \'antivirus_antivirus_featured_scaning\',
\'value\' => \'usb_virus_scan\',
\'compare\' => \'LIKE\'
);
if( isset( $_POST[\'registry_startup_scan\'] ) && $_POST[\'registry_startup_scan\'] == \'on\' )
$args[\'meta_query\'][] = array(
\'key\' => \'antivirus_antivirus_featured_scaning\',
\'value\' => \'registry_startup_scan\',
\'compare\' => \'LIKE\'
);
if( isset( $_POST[\'auto_virus_scanning\'] ) && $_POST[\'auto_virus_scanning\'] == \'on\' )
$args[\'meta_query\'][] = array(
\'key\' => \'antivirus_antivirus_featured_scaning\',
\'value\' => \'auto_virus_scanning\',
\'compare\' => \'LIKE\'
);
if( isset( $_POST[\'scheduled_scan\'] ) && $_POST[\'scheduled_scan\'] == \'on\' )
$args[\'meta_query\'][] = array(
\'key\' => \'antivirus_antivirus_featured_scaning\',
\'value\' => \'scheduled_scan\',
\'compare\' => \'LIKE\'
);
// antivirus_featured_threat
if( isset( $_POST[\'anti_spyware\'] ) && $_POST[\'anti_spyware\'] == \'on\' )
$args[\'meta_query\'][] = array(
\'key\' => \'antivirus_antivirus_featured_threat\',
\'value\' => \'anti_spyware\',
\'compare\' => \'LIKE\'
);
if( isset( $_POST[\'anti_worm\'] ) && $_POST[\'anti_worm\'] == \'on\' )
$args[\'meta_query\'][] = array(
\'key\' => \'antivirus_antivirus_featured_threat\',
\'value\' => \'anti_worm\',
\'compare\' => \'LIKE\'
);
if( isset( $_POST[\'anti_trojan\'] ) && $_POST[\'anti_trojan\'] == \'on\' )
$args[\'meta_query\'][] = array(
\'key\' => \'antivirus_antivirus_featured_threat\',
\'value\' => \'anti_trojan\',
\'compare\' => \'LIKE\'
);
if( isset( $_POST[\'anti_rootkit\'] ) && $_POST[\'anti_rootkit\'] == \'on\' )
$args[\'meta_query\'][] = array(
\'key\' => \'antivirus_antivirus_featured_threat\',
\'value\' => \'anti_rootkit\',
\'compare\' => \'LIKE\'
);
if( isset( $_POST[\'anti_phishing\'] ) && $_POST[\'anti_phishing\'] == \'on\' )
$args[\'meta_query\'][] = array(
\'key\' => \'antivirus_antivirus_featured_threat\',
\'value\' => \'anti_phishing\',
\'compare\' => \'LIKE\'
);
if( isset( $_POST[\'anti_spam\'] ) && $_POST[\'anti_spam\'] == \'on\' )
$args[\'meta_query\'][] = array(
\'key\' => \'antivirus_antivirus_featured_threat\',
\'value\' => \'anti_spam\',
\'compare\' => \'LIKE\'
);
if( isset( $_POST[\'email_protection\'] ) && $_POST[\'email_protection\'] == \'on\' )
$args[\'meta_query\'][] = array(
\'key\' => \'antivirus_antivirus_featured_threat\',
\'value\' => \'email_protection\',
\'compare\' => \'LIKE\'
);
if( isset( $_POST[\'chat_im_protection\'] ) && $_POST[\'chat_im_protection\'] == \'on\' )
$args[\'meta_query\'][] = array(
\'key\' => \'antivirus_antivirus_featured_threat\',
\'value\' => \'chat_im_protection\',
\'compare\' => \'LIKE\'
);
if( isset( $_POST[\'adware_prevention\'] ) && $_POST[\'adware_prevention\'] == \'on\' )
$args[\'meta_query\'][] = array(
\'key\' => \'antivirus_antivirus_featured_threat\',
\'value\' => \'adware_prevention\',
\'compare\' => \'LIKE\'
);
$query = new WP_Query( $args );
谢谢你的帮助。