The issue

A plugin shortcode displays a form underneath each post. Within the form thus displayed, there are numerous visible fields to be filled by users. There is also a hidden field to update a meta key visible on the back end only, with a place for value - as in image. I want to secretly pass the ID of the post (or title or name or slug etc) under which the form (by shortcode) is appearing, so I know at least where the form was even filled from.

Please consider modulating your solution so it can be understood by a beginner. (My question history shows)

I've tried a number of ways of using $post variable for the last 20 days - assuming its super global, using hooks, but a new session when submitting the form means I couldn't access the post data... either in functions.php file or the plugin PHP files - likewise sending data through PHP POST method seems like over exertion (it also places an extra submit button).

Im so lost for direction now!

I have access to $post in the Loop, on the individual post displayed - but I want any of the post attributes (ID/title/slug etc) to automatically STUFF into that one field when someone hits submit !!!?

Note: since $post is inaccessible, none of these work when directly placed in the value field: $post->ID $post->ID post_id $postid $post_id {$postid} {$post_id} the_ID ID get_the_ID(); the_title(); get_queried_object_id()

  • I'd recommend contacting the plugin author to ask if they support this - you're basically asking for dynamic fields. If the plugin doesn't explicitly support this, and if you're comfortable using JavaScript/jQuery, you could set the meta value in your screen shot to something like replaceme and using jQuery replace the value. That way at least visitors with JS enabled will submit with whichever post info you want. Or alternatively, you could set up Google Tag Manager to capture form submissions as a Google Analytics Event and capture the page URL they came from.
    – WebElaine
    Commented Mar 20, 2018 at 19:01
  • TY @WebElaine The Front End Submissions by EDD appears to be the only premium form that doesnt support dynamic fields! unimaginable - and one as common as a post ID - gravity and formidable etc all have this included. This is "custom work" and not supported by them either for support. Since JS dependence is a deal breaker, what about AJAX? I mean we have to have a way to stuff post ID into the shortcode at the time of form submission - or wouldnt there be a way to code this easily!? update_post_meta works in functions.php and in the plugin file with random values. Just no post info to replace
    – Ebe
    Commented Mar 20, 2018 at 19:11

1 Answer 1


If you put a unique placeholder value there, you can do a find/replace via the_content filter, which runs after the shortcode is rendered, but before the content is output in the template.

For example, this will replace any occurrence of replacethisthing with the post ID:

function wpd_replace_something_in_the_content( $content ){
    return str_replace( "replacethisthing", get_the_ID(), $content );
add_filter( 'the_content', 'wpd_replace_something_in_the_content', PHP_INT_MAX );
  • this updated the meta value of meta key 'license' with the value replacethisthing - the post ID would still not show. I pasted the code block in functions.php - would I have needed to add the filter elsewhere as well? The whole idea is making the changes in the database, updating a meta value - so I can link form submissions to the original post (then list them under the post). Would this only affect content output in template? Or would it make DB changes? Thanks
    – Ebe
    Commented Mar 21, 2018 at 9:14
  • Without seeing exactly how the form is generated and submitted, that’s the best I can do, sorry
    – Milo
    Commented Mar 21, 2018 at 13:37

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.