自定义WooCommerce产品查询

时间:2020-09-20 作者:Maxime

我从事的一个项目展示了一些旅行(取决于目的地类别)。我尝试在开始日期(var\\u confirmed\\u date)对旅行进行排序,但结果与未排序相同。

以下是我的疑问:

`$args = array(
                    \'posts_per_page\'    => -1,
                    \'post_type\'         => \'product\',
                    \'meta_value\'        =>  \'meta_value\',
                    \'meta_key\'          =>  \'var_confirmed_date\',
                    \'order\'             =>  \'ASC\',
                    \'meta_type\'         =>  \'DATE\',
                    \'tax_query\'         => array(
                        array(
                            \'taxonomy\'  => \'destination\',
                            \'field\'     => \'id\',
                            \'terms\'     => array($t_id)
                        )
                    ),
                    \'meta_query\' => array(
                        array(
                            \'key\'     => \'var_confirmed_date\',
                            \'value\'   => date("Y-m-d",time()),
                            \'compare\' => \'>=\',
                            \'type\'    => \'DATE\',
                        ),
                    ),
                );
            $loop = new WP_Query( $args );`
有没有办法让它正常工作?

谢谢

2 个回复
SO网友:Valerii Vasyliev

Try this

$args = array(
                    \'posts_per_page\'    => -1,
                    \'post_type\'         => \'product\',
                    \'meta_key\'          =>  \'var_confirmed_date\',
                    \'meta_type\'         =>  \'DATE\',
                    \'orderby\'           => \'meta_value_date\',
                    \'order\'             =>  \'ASC\',
                    \'tax_query\'         => array(
                        array(
                            \'taxonomy\'  => \'destination\',
                            \'field\'     => \'id\',
                            \'terms\'     => array($t_id)
                        )
                    ),
                    \'meta_query\' => array(
                        array(
                            \'key\'     => \'var_confirmed_date\',
                            \'value\'   => date("Y-m-d",time()),
                            \'compare\' => \'>=\',
                            \'type\'    => \'DATE\',
                        ),
                    ),
                );
            $loop = new WP_Query( $args );
SO网友:Maxime

我在StackExchange上找到了解决方案(WooCommerce: filter by parent product's taxonomy and product variation's meta data)

我在子函数中使用一个函数。php然后根据$t\\u id和函数中找到的id进行排序

相关推荐

从商店页面的前面部分删除Storefront-Sorting div

我已经发现,我可以使用以下方法从商店页面中删除排序下拉菜单和分页:function delay_remove() { remove_action( \'woocommerce_after_shop_loop\', \'woocommerce_catalog_ordering\', 10 ); remove_action( \'woocommerce_before_shop_loop\', \'woocommerce_catalog_ordering\', 10 ); remove_