Php 按全局/后端顺序排列Wordpress属性(orderby)
我正在尝试创建一个函数,在该函数中,所有可用的颜色(属性/术语)都会附加到每个产品-在类别页面(产品列表)上。下面的代码可以工作,但是前端订单与后端订单不同。我真的搞不清楚,我该如何对属性进行相应的排序。已尝试将Php 按全局/后端顺序排列Wordpress属性(orderby),php,wordpress,woocommerce,Php,Wordpress,Woocommerce,我正在尝试创建一个函数,在该函数中,所有可用的颜色(属性/术语)都会附加到每个产品-在类别页面(产品列表)上。下面的代码可以工作,但是前端订单与后端订单不同。我真的搞不清楚,我该如何对属性进行相应的排序。已尝试将菜单顺序更改为术语顺序。这也不行 function ea_display_color_swatches_on_category() { $html_swatch = '<div class="swatches-wrapper">'; $terms = wp_
菜单顺序
更改为术语顺序
。这也不行
function ea_display_color_swatches_on_category() {
$html_swatch = '<div class="swatches-wrapper">';
$terms = wp_get_object_terms( get_the_ID(), 'pa_farve', array( 'orderby' => 'menu_order' ) );
foreach ( $terms as $term ) {
$hex_color = get_woocommerce_term_meta( $term->term_id, 'pa_farve_swatches_id_color', true );
$html_swatch .= '<a class="swatch-color-category tooltips"
title="' . $term->name . '"
style="background:' . $hex_color . '" ></a>';
}
// end color-swatches-wrapper
$html_swatch .= '</div>';
echo $html_swatch;
}
add_action( 'woocommerce_before_shop_loop_item', 'ea_display_color_swatches_on_category' );
功能ea\u显示\u颜色\u样本\u类别(){
$html_样例=“”;
$terms=wp\u get\u object\u terms(获取\u ID(),'pa\u farve',数组('orderby'=>'menu\u order');
foreach($terms作为$term){
$hex\u color=get\u woodcommerce\u term\u meta($term->term\u id,'pa\u farve\u swatches\u id\u color',true);
$html_样本='
您是否尝试过使用term_id?WordPress用于按创建日期排序