$args Orderby The number

时间:2014-07-29 作者:inmortal

我有这个密码

$cat_args=array(
\'include\' => \'42,210,21\',
\'orderby\' => \'42,210,21\',
\'order\' => \'asc\'
 );
$categories=get_categories($cat_args);
  foreach($categories as $category) {
    $args=array(
     \'showposts\' => 1,
     \'category__in\' => array($category->term_id),
     \'caller_get_posts\'=>1
 );
我想要orderby 与…的顺序相同include, 不按姓名或id

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

您可以使用get_terms_orderby 过滤器:

add_filter( \'get_terms_orderby\', \'wpse156153_get_terms_orderby\', 10, 3 );
$categories=get_categories($cat_args);
remove_filter( \'get_terms_orderby\', \'wpse156153_get_terms_orderby\', 10, 3 );
使用

function wpse156153_get_terms_orderby($orderby, $args, $taxonomies ) {
    return \'FIELD(t.term_id, \' . $args[\'include\'] . \')\';
}

结束

相关推荐

Show category post order ASC

下面是我的分类。php页面代码。我想点菜ASC. 我怎样才能做到这一点?<div class=\"content\"> <?php if ( have_posts() ) : ?> <h2> <?php single_cat_title(\'\',true); ?> </h2> <ul class=\"products\"> <?php while ( have_posts() )