简体   繁体   English

从 PHP 查询中排除标签

[英]Exclude Tags from PHP Query

I have written the following query in my child themes functions.php file.我在我的子主题functions.php文件中编写了以下查询。

Currently this works exactly as it needs to however I wish to extend this query such that it excludes specific tags.目前这完全符合它的需要,但是我希望扩展这个查询,以便它排除特定的标签。

  'post_type' => 'product',
  'meta_key' => 'total_sales',
  'orderby' => 'meta_value_num',
  'posts_per_page' => 10,
  'tax_query' => array(
      array(
           'taxonomy' => 'product_tag',
           'terms' => 492,
           'field' => 'id',
      ),
   ),
); 

You can use 'compare' => 'NOT IN' .您可以使用'compare' => 'NOT IN'

'post_type'      => 'product',
'meta_key'       => 'total_sales',
'orderby'        => 'meta_value_num',
'posts_per_page' => 10,
'tax_query' => array(
    array(
       'taxonomy' => 'product_tag',
       'terms'    => array( 492, 422 ),
       'field'    => 'id',
       'compare'  => 'NOT IN'
    ),
),

USEFUL LINKS有用的链接

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM