Getting the list of the latests posts and custom type posts in the homepage

The post_type argument of the get_posts() function is for retrieving different types of post content. I’m assuming here that ‘work’, ‘photo’, and ‘code’ are custom post types.

Grabbing multiple post types with WP_Query

Instead of using get_posts(), you can use the WP_Query class to grab multiple post types. I just tested the following on my local install:

<?php

$q = new WP_Query(array(
    'post_type' => array('event', 'post')
));

while ($q->have_posts()) : $q->the_post();

?>

// ... the loop goes here as usual
<h1><?php the_title(); ?></h1>
<?php the_content(); ?>

<?php endwhile; ?>

This grabbed posts of type “event” and of type “post” for me and displayed them by date. You can learn a lot more about the WP_Query object on the codex page. There’s even a section specific to querying types and parameters.

Note that you do need to reference the object returned when instantiating the WP_Query object at the top of the loop with something like $q->, but you don’t need to do this inside of the loop.