How to display recent posts added in custom post types

The answer is essentially in Codex!

<h2>Recent Posts</h2>
<ul>
<?php
    $recent_posts = wp_get_recent_posts(array('post_type'=>'book'));
    foreach( $recent_posts as $recent ){
        echo '<li><a href="' . get_permalink($recent["ID"]) . '" title="Look '.esc_attr($recent["post_title"]).'" >' .   $recent["post_title"].'</a> </li> ';
    }
?>
</ul>

The only thing I did was add an argument to search for the book post type instead of the default post type.

And this is probably a duplicate of this question anyway, but the system won’t let me mark it as such.

Leave a Comment