hor*_*gaz 3 php wordpress woocommerce
我在 WooCommerce 上开一家鞋店。每双鞋都有不同的颜色和尺码。我添加了颜色和尺寸作为属性,然后添加了一些产品作为可变产品。
我想在商店页面中列出所有产品,仅包括颜色变化(不包括尺寸!)...示例:
然后,我的商店页面应该有四个项目:
第一步:我试图以商店页面主查询为目标来修改它,但我不能!我正在这样做:
function custom_pre_get_posts( $query ){
// attempt #1
if( ( 'product' == get_post_type() || is_post_type_archive('product') ) ):
$query->set( 'posts_per_page', '1' );
return;
endif;
// attempt #2
if( is_shop() ):
$query->set( 'posts_per_page', '1' );
return;
endif;
}
add_action('pre_get_posts', 'custom_pre_get_posts');
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?提前致谢!
第二步:我将尝试修改主查询以仅针对我之前提到的变体...我也不知道如何做到这一点...有任何提示吗?
谢谢!!
小智 5
为我工作
\n// ALTERAR A QUERY PRINCIPAL\nfunction fwp_archive_per_page( $query ) {\n if ( is_tax( 'product_cat' ) || is_post_type_archive('product') ) {\n \n $query->set( 'showposts', 16 );\n $query->set( 'posts_per_page', 16 );\n $query->set( 'meta_query', array(\n 'relation' => 'AND',\n array(\n 'key' => 'condicoes_de_exibicao',\n 'value' => array('N\xc3\xa3o exibir no site', 'N\xc3\xa3o exibir em lugar nenhum'),\n 'compare' => 'NOT IN',\n )\n ) );\n\n }\n}\nadd_filter( 'pre_get_posts', 'fwp_archive_per_page' );\nRun Code Online (Sandbox Code Playgroud)\n
| 归档时间: |
|
| 查看次数: |
5815 次 |
| 最近记录: |