class WOO_VPF_Hooks {
/**
* @var page_title
*/
public $page_title = '';
/**
* @var searched_term_id
*/
public $searched_term_id = '';
}
function filt_post_where( $where, $query ) {
// custom begin
if( ! is_admin() && $query->is_main_query() ) {
if( $this->searched_term_id && $this->searched_term_id > 0) {
global $wpdb;
$year_pid = $this->searched_term_id;
$model_pid = $wpdb->get_var("SELECT parent FROM $wpdb->term_taxonomy WHERE term_taxonomy_id = ".$year_pid.""); //7917
if($model_pid == 0){
$make_pid = $wpdb->get_var("SELECT parent FROM $wpdb->term_taxonomy WHERE term_taxonomy_id = ".$model_pid.""); //4591
$ot_year_id = $wpdb->get_results("SELECT term_taxonomy_id FROM $wpdb->term_taxonomy WHERE term_taxonomy_id !=".$year_pid." AND parent = ".$model_pid."");
$ot_num = count($ot_year_id);
$ot_year_arr = array();
for($i=0;$i<$ot_num;$i++){
$ot_year_arr[] = $ot_year_id[$i]->term_taxonomy_id;
}
if($make_pid == 0){
$ot_model_id = $wpdb->get_results("SELECT term_taxonomy_id FROM $wpdb->term_taxonomy WHERE term_taxonomy_id !=".$model_pid." AND parent = ".$make_pid."");
$ot_num2 = count($ot_model_id);
$ot_model_arr = array();
for($i=0;$i<$ot_num2;$i++){
$ot_model_arr[] = $ot_model_id[$i]->term_taxonomy_id;
}
}
}
$year_id = $wpdb->get_results("SELECT object_id FROM $wpdb->term_relationships WHERE term_taxonomy_id = ".$year_pid."");
$year_num = count($year_id);
$filter_array = array();
for($i=0;$i<$year_num;$i++){
$filter_array[] = $year_id[$i]->object_id;
}
if($model_pid == 0){
$model_id = $wpdb->get_results("SELECT object_id FROM $wpdb->term_relationships WHERE object_id NOT IN ( '" . implode( "', '" , $filter_array ) . "' ) AND term_taxonomy_id = ".$model_pid."");
$model_num = count($model_id);
for($i=0;$i<$model_num;$i++){
$now_id = $model_id[$i]->object_id;
$have_cat = $wpdb->get_var("SELECT count(object_id) FROM $wpdb->term_relationships WHERE object_id = ".$now_id." AND term_taxonomy_id IN ('" . implode( "', '" , $ot_year_arr ) . "')");
if($have_cat == 0){
$filter_array[] = $now_id;
}
}
if($make_pid == 0){
$make_id = $wpdb->get_results("SELECT object_id FROM $wpdb->term_relationships WHERE object_id NOT IN ( '" . implode( "', '" , $filter_array ) . "' ) AND term_taxonomy_id = ".$make_pid."");
$make_num = count($make_id);
for($i=0;$i<$make_num;$i++){
$now_fid = $make_id[$i]->object_id;
$have_pcat = $wpdb->get_var("SELECT count(object_id) FROM $wpdb->term_relationships WHERE object_id = ".$now_fid." AND term_taxonomy_id IN ('" . implode( "', '" , $ot_model_arr ) . "')");
if($have_pcat == 0){
$filter_array[] = $now_fid;
}
}
}
}
$universal = WC_Admin_Settings::get_option("woo_vpf_taxonomy_metabox_excluded_products");
$first_filter = array_merge($filter_array,$universal);
$final_filter = array_unique($first_filter);
$where = preg_replace( '!\s+!', ' ', $where );
$where = str_replace( "$wpdb->posts.ID NOT IN ( SELECT object_id FROM wp_term_relationships WHERE term_taxonomy_id IN (7) )", "$wpdb->posts.ID IN('" . implode( "', '" , $final_filter ) . "')", $where );
}
}
//custom end
return $where;
}
Phperrorcode:
WordPress数据库错误您的SQL语法有错误;检查与您的MySQL服务器版本对应的手册以获取正确的语法,以在第1行的''附近使用SELECT SELECT term_taxonomy_id FROM wp_term_taxonomy WHERE term_taxonomy_id!= 0 AND parent =由require('wp-blog-header.php')制成,wp,WP-> main,WP-> query_posts,WP_Query-> query,WP_Query-> get_posts
是否提到我在运行此代码或其他内容之前必须先包含wp-blog-header.php文件。