Grab 5 latest posts from custom post type ‘announcements’

The following should work, but isn’t tested:

<div id="header-announcements">
<h3>Announcements</h3>
<?php
$queryObject = new WP_Query( 'post_type=announcements&posts_per_page=5' );
// The Loop!
if ($queryObject->have_posts()) {
    ?>
    <ul>
    <?php
    while ($queryObject->have_posts()) {
        $queryObject->the_post();
        ?>

        <li><a href="https://wordpress.stackexchange.com/questions/26482/<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
    <?php
    }
    ?>
    </ul>
    <div><a href="#">View More</a></div>
    <?php
}
?>
</div>

Leave a Comment