基于this 我尝试将以下代码编写为:
Custom Page template:
/*
Template Name: product_filter
*/
get_header();
do_action( \'pre_get_posts\', \'COOLING\');
Functions.php
add_action(\'pre_get_posts\',\'shop_filter_cat\',10,1);
function shop_filter_cat($query, $arg) {
if (!is_admin() && is_post_type_archive( \'product\' ) && $query->is_main_query()) {
$query->set(\'tax_query\', array(
array (\'taxonomy\' => \'product_cat\',
\'field\' => \'slug\',
\'terms\' => $arg
)
)
);
}
}
但我得到以下警告:
警告:在E:\\xampp\\htdocs\\wordpress\\wp includes\\plugin中调用的shop\\u filter\\u cat()缺少参数2。php位于第600行,在E:\\xampp\\htdocs\\wordpress\\wp content\\themes\\storefront\\functions中定义。php在线56
和错误:
致命错误:未捕获错误:对成员函数的调用是E:\\xampp\\htdocs\\wordpress\\wp content\\plugins\\woodcommerce\\includes\\wc弃用函数中字符串上的\\u main\\u query()。php:677堆栈跟踪:#0 E:\\xampp\\htdocs\\wordpress\\wp includes\\plugin。php(524):wc\\u shop\\u order\\u status\\u backwards\\u compatibility(“COOLING”)\\1 E:\\xampp\\htdocs\\wordpress\\wp content\\themes\\storefront\\testing。php(6):do\\u action(\'pre\\u get\\u posts\',\'COOLING\')\\2 E:\\xampp\\htdocs\\wordpress\\wp includes\\template loader。php(75):包括(\'E:\\xampp\\htdocs…\')\\3 E:\\xampp\\htdocs\\wordpress\\wp blog header。php(19):require\\u once(\'E:\\xampp\\htdocs…\')\\4 E:\\xampp\\htdocs\\wordpress\\index。php(17):在E:\\xampp\\htdocs\\wordpress\\wp content\\plugins\\woodcommerce\\includes\\wc弃用函数中抛出的require(\'E:\\xampp\\htdocs…\')\\5{main}。php在线677