【问题标题】:Woocommerce order categories by category order as per admin section根据管理部分按类别订单分类的 Woocommerce 订单类别
【发布时间】:2014-10-02 08:27:36
【问题描述】:

在 woocommerce 类别屏幕中,您可以拖放类别以更改其顺序。

在“前端”中,我想以相同的顺序列出类别(与 wp-admin 中产品类别屏幕的拖放相同的自定义顺序)。

$args = array(
  'taxonomy'     => 'product_cat',
  'orderby'      => 'term_order',
  'order'        => 'asc',
  'show_count'   => 0,
  'pad_counts'   => 0,
  'hierarchical' => 1,
  'title_li'     => '',
  'hide_empty'   => 0,
);

$query = new WP_Query( $args );

我尝试了几种不同的 orderby 变体,但无法获得与管理屏幕完全相同的订单。订购数据似乎存储在 ??__woocommerce_termmeta 表中,其中 'meta_key' 为 'order'。

任何建议将不胜感激。

谢谢。

【问题讨论】:

    标签: wordpress woocommerce


    【解决方案1】:

    似乎 WooCommerce 已经在更改 product_cat 分类的查询。例如:

    $args = array(
        'parent'        => 0,
        'taxonomy'      => 'product_cat'
    );
    
    $categories = get_categories( $args );
    

    执行的查询将如下所示:

    SELECT t., tt., tm.* FROM wp_terms AS t INNER JOIN wp_term_taxonomy AS tt ON t.term_id = tt.term_id 左加入 wp_woocommerce_termmeta AS tm ON (t.term_id = tm.woocommerce_term_id AND tm.meta_key = 'order') WHERE tt.taxonomy IN ('product_cat') AND tt.parent = '0' ORDER BY tm.meta_value+0 ASC, t.name ASC

    类别的排列顺序与管理部分的顺序相同。

    【讨论】:

    • 谢谢,从来没有解决这个问题,因为代码中总是有一个 orderby。干杯!
    猜你喜欢
    • 2015-07-16
    • 1970-01-01
    • 2013-10-16
    • 2020-10-15
    • 2013-09-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多