1

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

1
  • 2
    Please .... show you full code here instead of linking to a tutorial. This is lazy and just adds to the number of questions that suffer from link rot
    – kaiser
    Commented Dec 17, 2013 at 15:37

3 Answers 3

13

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.

0
1

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 ); 
0
0

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')));

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.