Php Wordpress woocommerce多个orderby参数循环
有人知道如何将while循环合并到基本的orderby过滤器中吗?在我的functions.php页面中,我有以下基本过滤器,可以按功能产品订购我的产品,并且可以正常工作:Php Wordpress woocommerce多个orderby参数循环,php,arrays,wordpress,loops,woocommerce,Php,Arrays,Wordpress,Loops,Woocommerce,有人知道如何将while循环合并到基本的orderby过滤器中吗?在我的functions.php页面中,我有以下基本过滤器,可以按功能产品订购我的产品,并且可以正常工作: add_filter('woocommerce_get_catalog_ordering_args', 'am_woocommerce_catalog_orderby'); function am_woocommerce_catalog_orderby( $args ) { if(!$_GET['orderby'])
add_filter('woocommerce_get_catalog_ordering_args', 'am_woocommerce_catalog_orderby');
function am_woocommerce_catalog_orderby( $args ) {
if(!$_GET['orderby']) {
$args = array(
'orderby' => array( 'meta_value' => 'DESC' ),
'meta_key' => '_featured'
);
return $args;
}
}
我的问题是我想使用一些更高级的while循环来尝试将多个不同的参数绑定到同一个参数中。我尝试先显示我的特色产品,然后将其加载到数组中,然后获取下一个循环,只显示6个月或更年轻的产品,并将其添加到我的数组中,然后显示所有其他内容,并按菜单顺序和标题对其排序,然后将其添加到我的数组中,如下所示:
add_filter('woocommerce_get_catalog_ordering_args', 'am_woocommerce_catalog_orderby');
function am_woocommerce_catalog_orderby( $my_post_array ) {
if(!$_GET['orderby']) {
//First loop - show featured
$args['orderby'] = array( 'meta_value' => 'DESC' );
$args['meta_key'] = '_featured';
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
$post_id = get_the_ID();
$my_post = my_post_function($post_id);
//Store the items in an array
$my_post_array [] = $my_post;
query_posts($args);
endwhile;
wp_reset_query();
//Second loop - Show newer than 6 months
$args = array(
'orderby' => 'date',
'order' => 'DESC',
'date_query' => array(
array(
'before' => '6 months ago',
),
)
);
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
$post_id = get_the_ID();
$my_post = my_post_function($post_id);
//Store the items in an array
$my_post_array [] = $my_post;
query_posts($args);
endwhile;
wp_reset_query();
//Third loop - show everything else and sort by menu_order and title
$args['orderby'] = array( 'menu_order' => 'ASC', 'title' => 'ASC' );
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
$post_id = get_the_ID();
$my_post = my_post_function($post_id);
//Store the items in an array
$my_post_array [] = $my_post;
query_posts($args);
endwhile;
wp_reset_query();
//Remove duplicate entries from the array
array_unique ( $my_post_array, SORT_STRING );
}
}
然后我要做的最后一件事就是删除我的副本。唯一的问题是它不起作用,我不知道我哪里出了问题,我以前没有做过这样的事情,所以我可能在错误的领域工作,或者遗漏了一些明显的东西。有人对我如何解决这个问题有想法吗,或者有人看到了可能会给我带来问题的东西吗?感谢您的帮助,我们仍在学习并努力提高