(WP)如何列出自定义帖子类型的所有帖子?
问题描述:
How to list all post from custom post types? Such as, post types = videos
I want list all post title + id of post from this post types only. Thanks. :D
如何列出自定义帖子类型的所有帖子? 例如,帖子类型=视频 p>
我想列出所有帖子标题+仅来自此帖子类型的帖子ID。 谢谢。 :D p> div>
答
This should work for you:
<?php
global $post;
$myposts = get_posts('post_type=videos&posts_per_page=-1');
foreach($myposts as $post) : setup_postdata($post);
?>
<h1><?php echo get_the_ID(); ?>, <?php the_title(); ?></h1>
<?php endforeach; ?>
The above should list out the ids
and the titles
of all the posts in the videos
post type.