如何按顺序显示wordpress帖子" title"

时间:2014-07-17 15:59:49

标签: php wordpress

我用这个函数来获取slug naruto chapitre 005

的类别帖子
$myposts = get_posts(array(
    'showposts' => -1,
    'post_type' => 'post',
    'tax_query' => array(
        array(
        'taxonomy' => 'category',
        'field' => 'slug',
        'terms' => array('naruto_chapitre_005'))
    ))
);



foreach ($myposts as $mypost) {
      echo $mypost->post_title . '<br/>';
}

//output
04
01
05
02
03

如何按订单获取帖子? 像这样 01 02 03 04 05

2 个答案:

答案 0 :(得分:2)

试试这个

$myposts = get_posts(array(
        'posts_per_page' => -1,
        'post_type' => 'post',
        'order'     => 'ASC',
        'orderby'   => 'title',
        'tax_query' => array(
            array(
            'taxonomy' => 'category',
            'field' => 'slug',
            'terms' => array('naruto_chapitre_005'))
        ))
    );

答案 1 :(得分:2)

使用值orderby的{​​{1}}属性:

title