How to add (Previous Post ID +1) for wordpress post title

I made a custom post_type in my wordpress site. Now trying to create a post object with special Title for each post.

Example : I want to use post title as Previous post ID +1

Read More

I tried that code :

// Create post object

$last = wp_get_recent_posts( '1');
$last_id = $last['0']['ID']+1;


$my_post = array(
  'post_title'    => 'Order'.$last_id,
  'post_content'  => 'This is my post.',
  'post_status'   => 'publish',
  'post_author'   => 1,
 'post_type' => 'fp-orders'
);

But there post tile not adding +1 number. It does returning always same Title. What my wrong in the following code above?

Please give me suggestion.

THanks in advance

Related posts

Leave a Reply

2 comments

  1. $recent_posts = wp_get_recent_posts( array( 'numberposts' => '1', 'post_type' => 'yourcustopmposttype' ) );
    $last_id = $recent_posts[0]['ID']+1;
    

    try this code please. You forgot to add post_type in your code.. that’s why you are not getting result.

  2. $last = wp_get_recent_posts( array( 'numberposts' => '1' ) );
    $last_id = $recent_posts[0]['ID']+1;
    

    please try my code and let me know if it works….