WP_Query:从WooCommerce产品列表中排除隐藏的产品
-
-
我要指出的是,由于将posts_per_page设置为-1,该代码最终将灾难性地失败.当有1000个帖子时,很少有服务器会处理此代码,请不要介意20,000.乘以有多少访客到达您的网站I would note that this code will eventually fail catastrophically due to the `posts_per_page` being set to `-1`. Few servers would handle this code when there are 1000 posts, nevermind 20,000. Multiply that by however many visitors arrive on your site
- 0
- 2016-12-03
- Tom J Nowell
-
2 个回答
- 投票数
-
- 2016-06-30
重要:以下内容仅适用于WooCommerce版本低于3.0的版本.有关最新答案,请参阅其他卡尔的答案.
WooCommerce将此数据另存为
metadata
,因此您需要运行名称为_visibility
的"元查询" .像这样:'meta_query' => array( array( 'key' => '_visibility', 'value' => 'hidden', 'compare' => '!=', ) )
这将删除所有不具有等于
_visibility
的元_visibility
的帖子.Important: The following only works for WooCommerce versions less than 3.0. For a more up-to-date answer please see the other answer by kalle.
WooCommerce save this data as
metadata
so you'll need to run a Meta Query against the name_visibility
. Something like:'meta_query' => array( array( 'key' => '_visibility', 'value' => 'hidden', 'compare' => '!=', ) )
This will pull all posts that do not have meta
_visibility
equal tohidden
.-
完善.那就是我所需要的.对于搜索此答案的任何人,这是上面的完整查询. ` -1,'post_type'=>'product','orderby'=>'menu-order','order'=>'asc','meta_query'=> array( 数组( 'key'=>'_visibility', '值'=>'隐藏', '比较'=>'!=', ) )); $ wc_query=新的WP_Query($params); ?>`Perfect. That's what I needed. For anyone who searches for this answer, here is the full query to the above. ` -1, 'post_type' => 'product', 'orderby' => 'menu-order', 'order' => 'asc', 'meta_query' => array( array( 'key' => '_visibility', 'value' => 'hidden', 'compare' => '!=', ) )); $wc_query = new WP_Query($params); ?>`
- 0
- 2016-06-30
- Peter Ingersoll
-
@PeterIngersoll仅供参考,您可以将此答案标记为已接受,以向未来的访问者展示对您也有用的方法:) Howdy答案的左侧有一个复选标记.在此处了解更多信息:http://wordpress.stackexchange.com/help/someone-answers@PeterIngersoll FYI, you can mark this answer as accepted to show future visitors what worked for you as well :) There's a check mark on the left of Howdy's answer. Read more here: http://wordpress.stackexchange.com/help/someone-answers
- 0
- 2016-07-05
- Tim Malone
-
- 2017-04-06
从Woocommerce 3开始.可见性为已更改为分类法,而不是meta .因此,您需要将meta_query更改为tax_query. 要仅显示可见产品,
'tax_query' => array( array( 'taxonomy' => 'product_visibility', 'field' => 'name', 'terms' => 'exclude-from-catalog', 'operator' => 'NOT IN', ), ),
和特色产品示例
'tax_query' => array( array( 'taxonomy' => 'product_visibility', 'field' => 'name', 'terms' => 'featured', ), ),
可能的术语:"从搜索中排除","从目录中排除","精选","缺货".
As of Woocommerce 3. Visibility is changed to taxonomy instead of meta. So you need to change the meta_query to tax_query. To show only visible products,
'tax_query' => array( array( 'taxonomy' => 'product_visibility', 'field' => 'name', 'terms' => 'exclude-from-catalog', 'operator' => 'NOT IN', ), ),
and examples for Featured Products
'tax_query' => array( array( 'taxonomy' => 'product_visibility', 'field' => 'name', 'terms' => 'featured', ), ),
Possible terms: 'exclude-from-search', 'exclude-from-catalog', 'featured', 'outofstock'.
我希望这不是WooCommerce特有的.
我有一个漂亮的简码,显示我所有带有SKU的产品的列表.但是,它还包括我已发布但将目录可见性设置为"隐藏"的产品.
我找不到用于排除隐藏产品(或仅包括标记为Catalog/Search的产品)的参数/参数.
我知道这一定很简单;我只是没有找到它.感谢您的帮助.
代码如下: