WordPress/WooCommerce:将product_variation添加到搜索参数正在提取草稿产品
我有一家WooCommerce商店要化妆,我们需要做到这一点,以便可以搜索变化名称,因为人们通常会寻找特定的阴影名称。我正在使用这一点代码来使产品变化可以搜索:
add_action( 'pre_get_posts', 'search_woocommerce_product_variations' );
function search_woocommerce_product_variations( $query ) {
if( ! is_admin() && is_search() && $query->is_main_query() ) {
$query->set( 'post_type', array( 'post', 'page', 'product', 'product_variation' ) );
}
}
编辑以添加:我已经尝试添加此信息,而搜索结果没有更改:
$query->set('post_status', array('publish'));
问题是,在以变化的名称搜索时,它正在拉动。 UP在变体名称中具有该搜索词的产品,但目前已设置为草案状态。我如何防止这种情况发生?
I have a WooCommerce store for makeup, and we need to make it so that variation names are searchable, since people will often be looking for a specific shade name. I'm using this bit of code to make the product variations searchable:
add_action( 'pre_get_posts', 'search_woocommerce_product_variations' );
function search_woocommerce_product_variations( $query ) {
if( ! is_admin() && is_search() && $query->is_main_query() ) {
$query->set( 'post_type', array( 'post', 'page', 'product', 'product_variation' ) );
}
}
Edited to add: I've already tried adding this in, with no changes in the search results:
$query->set('post_status', array('publish'));
The problem is that when searching on the name of a variation it's pulling up products that do that have that search term in the variation name, but are currently set to Draft status. How can I prevent that from happening?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
告诉查询您要寻找的post_status:
Tell the query which post_status your looking for: