i used this function to get posts of category withe 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
how to get the posts by order ? like this 01 02 03 04 05
Try this
$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'))
))
);
Use the orderby
attribute with the value title
:
$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'))
))
);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.