Updated 10 hours later: enriched with alternative solution and complemented with comments.
<?php
/* ******* Built-in post type "Post" ******* */
$arguments_for_posts = array(
'numberposts' => 1, // number of posts to get
'post_type' => 'post' // post type
);
// get the array of post objects
$posts = get_posts( $arguments_for_posts );
// iterate through array to get individual posts
foreach( $posts as $post ) {
// Enclosing block having unique ID
echo '<article id="post-' . $post->ID . '">';
// Post title (property of $post object)
echo '<h1>' . $post->post_title . '</h1>';
// Post content (property of $post object)
echo $post->post_content;
echo '</article>';
}
/* ******* Custom post type "Feature" ******* */
$arguments_for_features = array(
'numberposts' => 1,
'post_type' => 'features'
);
$features = get_posts( $arguments_for_features );
foreach( $features as $feature ) {
echo '<article id="feature-' . $feature->ID . '">';
echo '<h1>' . $feature->post_title . '</h1>';
echo $feature->post_content;
echo '</article>';
}
Or you can use two WP_Queries when loops will look more familiar:
<?php
/* ******* Built-in post type "Post" ******* */
// Arguments
$args = array(
'posts_per_page' => 1,
'post_type' => 'post',
);
// The query
$query_posts = new WP_Query( $args );
// The loop
while ( $query_posts->have_posts() ) {
$query_posts->the_post();
?>
<article id="post-<?php the_ID(); ?>">
<h1><?php the_title(); ?></h1>
<?php the_content(); ?>
</article>
<?php
} // END while()
// Essential!
// Set the post data back up
wp_reset_postdata();
/* ******* Custom post type "Feature" ******* */
$args = array(
'posts_per_page' => 1,
'post_type' => 'feature',
);
$query_features = new WP_Query( $args );
while ( $query_features->have_posts() ) {
$query_features->the_post();
?>
<article id="feature-<?php the_ID(); ?>">
<h1><?php the_title(); ?></h1>
<?php the_content(); ?>
</article>
<?php
} // END while()
?>
Thanks @Qaisar Feroz for the useful reminder.
Useful links: