I have tried a code posted here>>Custom Post Type: Get most recent permalink
But the thing is-it is showing only one post from the recent and without get_the_title,,, can anyone help me to achieve, upto 10 posts' Title and permalink of custom post type.
I am googling from about 1 hour.. Please anyone help me
I have tried a code posted here>>Custom Post Type: Get most recent permalink
But the thing is-it is showing only one post from the recent and without get_the_title,,, can anyone help me to achieve, upto 10 posts' Title and permalink of custom post type.
I am googling from about 1 hour.. Please anyone help me
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.
Assuming you know how to use WP_Query, you can use following code to get recent 10 posts for any custom post type .
$args = array(
'post_type' => 'your-custom-post-type',
'orderby' => 'date',
'order' => 'DESC',
'posts_per_page' => 10
);
$query = new WP_Query( $args );
You can use this code to get recent posts
$recent_posts = get_posts( array( 'posts_per_page' => 1, 'orderby' => 'post_date', 'order'=> 'DESC', 'post_type' => array('camp','cruise','competition','combine')));
Can also add this code. Must add the 'post_status' => 'publish' in the array code.
<?php
$recent_posts = wp_get_recent_posts(array('numberposts' => 100, 'post_status' => 'publish', 'post_type'=>'book'));
foreach( $recent_posts as $recent ){
echo '<a href="' . get_permalink($recent["ID"]) . '" title="Look '.esc_attr($recent["post_title"]).'" >' . $recent["post_title"].'</a> ';
}?>