Wordpress 获取自定义文章类型的文章列表

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
$args = array( 
'numberposts' => -1, // -1 is for all
'post_type' => 'movie', // or 'post', 'page' 文章类型
'orderby' => 'ID', // or 'date', 'rand'
'order' => 'ASC', // or 'DESC'
);

// Get the posts
$myposts = get_posts($args);
if($myposts){
foreach($myposts as $mypost){
echo $mypost->ID.' '.get_the_title($mypost->ID);
}
wp_reset_postdata();
}
Reference
  1. SHOWING A LIST OF CUSTOM POST TYPE USING GET_POSTS() LOOP IN WORDPRESS