下面的代码 19 工作正常,因为它是从 woocommerce 网站复制的。不幸的是,我无法将 19 替换为 $producten 以便 $producten 包含一个包含所有类别的数组。
$producten 包含多个需要隐藏并在数据库中定义的类别。我想做什么以及如何做有可能吗?
$userid = get_current_user_id();
$result = mysql_query("SELECT productID FROM bestellingen WHERE userID='$userid'");
$producten = array();
while($row = mysql_fetch_array($result)){
array_push($producten, $row['productID']);
}
add_action( 'pre_get_posts', 'custom_pre_get_posts_query' );
function custom_pre_get_posts_query( $q ) {
if ( ! $q->is_main_query() ) return;
if ( ! $q->is_post_type_archive() ) return;
if ( ! is_admin() && is_shop() ) {
$q->set( 'tax_query', array(array(
'taxonomy' => 'product_cat',
'field' => 'slug',
'terms' => array( 19 ), // de categorienummers
'operator' => 'NOT IN'
)));
}
remove_action( 'pre_get_posts', 'custom_pre_get_posts_query' );
}
提前致谢!