如何在自定义字段(分类)中以非字母顺序显示产品名称?

时间:2013-01-23 作者:Blanka

现在的顺序是:apples, oranges, pears.<但我想按随机顺序排列,例如:oranges, apples, pears.<或者按照我想要的顺序来写。

这可能吗?

分类法如下:

        \'fruits\' => array(
        \'post-types\' => array(\'products\'),
        \'name\' => \'Fruits\',
        \'slug\' => \'fruits\',
        \'type\' => \'tags\' ),

1 个回复
最合适的回答,由SO网友:Blanka 整理而成

[SOLVED] This do the Job:

function set_the_terms_in_order ( $terms, $id, $taxonomy ) {
    $terms = wp_cache_get( $id, "{$taxonomy}_relationships_sorted" );
    if ( false === $terms ) {
        $terms = wp_get_object_terms( $id, $taxonomy, array( \'orderby\' => \'term_order\' ) );
        wp_cache_add($id, $terms, $taxonomy . \'_relationships_sorted\');
    }
    return $terms;
}
add_filter( \'get_the_terms\', \'set_the_terms_in_order\' , 10, 4 );

function do_the_terms_in_order () {
    global $wp_taxonomies;  //fixed missing semicolon
    // the following relates to tags, but you can add more lines like this for any taxonomy
    $wp_taxonomies[\'post_tag\']->sort = true;
    $wp_taxonomies[\'post_tag\']->args = array( \'orderby\' => \'term_order\' );    
}
add_action( \'init\', \'do_the_terms_in_order\');
Credit goes here: Change order of Custom Taxonomy List

结束

相关推荐

Page for custom taxonomy

我是WordPress的新手,我刚刚在一个名为arts的自定义帖子类型下创建了一个名为categories的新自定义分类法。有没有办法创建一个自定义页面来显示“类别”的自定义类型?这样,用户可以导航到艺术/类别,并查看类别分类法下的所有术语。