📜  pre_get_posts 通过标签 php\ 获取产品 - PHP 代码示例

📅  最后修改于: 2022-03-11 14:54:16.651000             🧑  作者: Mango

代码示例1
add_action('pre_get_posts','shop_filter_cat');

 function shop_filter_cat($query) {
    if (!is_admin() && is_post_type_archive( 'product' ) && $query->is_main_query()) {
       $query->set('tax_query', array(
                    array ('taxonomy' => 'product_cat',
                                       'field' => 'slug',
                                        'terms' => 'type-1'
                                 )
                     )
       );   
    }
 }