How do I pass a post ID to the page URL?

I am using a form (gravity form) on my site. The form is inserted in a page (called form_page) on the users dashboard when they are logged in

http://example.com/dashboard/form_page

Read More

I am using a plugin (see below) to dynamically populate the form with content from the post the user is author to. However I need to pass the POST ID to the URL for it to work.

So the URL would end up looking like this

http://example.com/dashboard/form_page?gform_post_id=476

This works.

However, I am manually appending the ?gform_post_id=476 to the end of the URL to test the concept actually works and it does. However I have no idea how to dynamically pass this post ID to the end of the URL of the page for an Author who is logged in.

It might help to know that the “Author” will only have 1 post associated with them. So (out loud) I am thinking there might be a way to GET the POST_ID associated with the logged in USER and then pass it to the URL of that particular page.

I am just not sure how to connect the missing piece of this puzzle and would appreciate some guidance.

Cheers in advance…

My effort so far is as follows

<?php foreach(get_posts(array('author' => $author_id)) as $post)?>
<a href="http://example.com/dashboard/form_page?gform_post_id=<?php echo $post->ID ?>">Link</a>

But this seems to get first POST ID the site. Not the ID of the Authors POST. Note: It is a custom post.

Plugin used: http://wordpress.org/extend/plugins/gravity-forms-update-post/

Related posts

Leave a Reply

1 comment

  1. First of all. The question is a little misleading. What you actually want is “post id(s) for current user”.

    Here we go:

    // Global variable for current user ID
    // More information: http://codex.wordpress.org/Function_Reference/get_currentuserinfo
    $user_ID;
    
    // You need to create a new WP query object
    // More info: http://codex.wordpress.org/Class_Reference/WP_Query
    $my_query = new WP_Query( array(
        'post_type' => 'farmers',
        'author' => $user_ID
    ));
    
    // You get all the current user posts from the query object
    $posts = $my_query->posts;
    
    // You get the first post from the posts array
    $first_post = $posts[0];
    
    // You get the post ID from post object and store it to $gform_post_id variable
    $gform_post_id = $first_post->ID;
    

    Now you can echo that $gform_post_id in your URL

    echo 'http://example.com/dashboard/form_page?gform_post_id='.$gform_post_id;
    

    Cheers