我创建了一个显示产品的循环,但在尝试过滤产品时遇到了问题。我添加了tax\\u查询,因为这是使用分类法过滤搜索的方法(根据我的理解)。我已获得当前URL术语以进行筛选$term_search = get_queried_object()->slug;
我还进行了$term\\u搜索,以确保输出的信息正确。
如何使过滤器正常工作?值得一提的是,我已经更改了类别的永久链接,这会影响我的slug吗?
$term_search = get_queried_object()->slug;
// WP_Query arguments
$args = array(
\'p\' => \'product\',
\'post_type\' => array( \'product\' ),
\'order\' => \'ASC\',
\'post_per_page\' => 20,
\'tax_query\' => array(
\'taxonomy\' => \'product_cat\',
\'field\' => \'slug\',
\'terms\' => $term_search, // (the name of what you want to filter by (latest or whatever))
\'include_children\' => true,
\'operator\' => \'IN\'
),
);
最合适的回答,由SO网友:davidb3rn 整理而成
我缺少tax\\u查询数组中数组的条件。无论您是否有一个或多个条件,都必须拥有它。
$term_search = get_queried_object()->slug;
// WP_Query arguments
$args = array(
\'p\' => \'product\',
\'post_type\' => array( \'product\' ),
\'order\' => \'ASC\',
\'post_per_page\' => 20,
\'tax_query\' => array(array(
\'taxonomy\' => \'product_cat\',
\'field\' => \'slug\',
\'terms\' => $term_search, // (the name of what you want to filter by (latest or whatever))
\'include_children\' => true,
\'operator\' => \'IN\'
)),
);