How to print all posts of a given post-type (CPT) in a given webpage?

You could use get_posts() to get posts of a particular type, then use a for loop to print out links, titles, etc as required.

Maybe put this in a custom template for your “All book pages” page. More info on templates here.

Example:

$posts = get_posts(array(
    "post_type"=>"book_pages",
    "post_status"=>"publish",
    "posts_per_page"=>-1 
));

if ($posts && count($posts)>0) 
{
    global $post;
    foreach ($posts as $post)
    {
        setup_postdata($post);
        the_title(); //prints out the title of this post
    }
    wp_reset_postdata(); 
}

Leave a Comment