0

I have a site setup so users can publish a post via the frontend, what happens is, there post is posted as a status, 'Pending Review, in a custom post type.

How can i get the post ID for this particular post the user has just published?

The posts author status is also set to the particular user that submitted the post.

I can get the author's ID using this.

$user_ID = get_current_user_id(); 

Hope this makes sense and thanks for the help.

  • Are you not using wp_insert_post function to create post? This function returns the ID of created post. – Nilambar Apr 20 '15 at 10:16
  • Thanks for the comment, no i'm using the gravityforms plugin where the users can publish posts via the frontend. Basically some code that finds the post from the authous ID and gets the posts ID is what i'm researching for.. :) – Shoebox Apr 20 '15 at 10:58
0

So digging around a little i couldn't find a solution where the WP_Query wasn't used, so i just stuck with the query method, Using WP_Query this snippet will display the latest post that is published by the user that is logged in.

$user_id = get_current_user_id();

$args=array(
    'post_type' => 'POSTTYPE',
    'post_status' => 'published',
    'posts_per_page' => 1,
    'author' => $user_id
);                       

$wp_query = new WP_Query($args);
while ( have_posts() ) : the_post(); 
    the_title();
endwhile; 

Hope this helps someone.

Cheers

Matt

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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