Hi, hoping this is within the scope of support you can reasonably give. I'm trying my hand at using of the developer hooks to achieve some stuff not available out of the box. I'm trying to achieve the following:
I have a loop containing posts from a custom post type (created by a specific author using a gravity form - no problems with this, all working as it should)
Each item in this loop is a job post that has an expiry date (so that the system knows when to turn it into a draft). This expiry date is calculated using the date of publication/posting and adding either 14, 30 or 45 days depending on what the user selected when they posted (again no problems with the logic for this - I have it all working elsewhere).
For each item in this loop I want to have a link that takes the user to a gravity form that allows them to update the expiry date by adding an extension of either 5, 10 or 15 days. The system would then add this many days to the current expiry date associated with that post (in a custom field) and update the post.
Having scoured the documentation and forums I've got as far as the code below:
<?php
// Updates expiration field on post extension form
add_action("gform_post_submission_4", "form_update_expiry_date", 10, 2);
function form_update_expiry_date($entry,$form){
$targetPost = $entry["1"]; //Gets the value of form field which is dynamically populated with the post ID passed to it via a query string
$new_date = $entry["2"]; //Gets the value of form field containing a new date - this is not really what I need though - did this more for a proof of concept
global $wpdb;
$wpdb->query("UPDATE $wpdb->postmeta SET meta_value= '$new_date' WHERE post_id=$targetPost AND meta_key='expiry date'");
}
?>
I'm using a query string to grab the ID of the post that the form should edit and passing that to a variable to use later in the wpdb query.
The biggest problem with the above block of code is that I need to somehow get the custom field value for the current expiry date. At the moment the code just doesn't really do what I need it to do and I'm really not sure that I'm doing things in the most straightforward way.
My question is this:
How would I pass the ID of the post to be edited to the form so that I can access values within that posts custom fields (assuming this can even be done?). It's just occurred to me that I could probably pass the expiry date custom field value to the form using a query string though that would leave it open to URL manipulation (someone could change the date or ID which isn't great).
Any pointers would be great - can probably muddle through once I know how to pass the ID to the function above is a more robust way (maybe using the Gform field value hook to pass the value to the form then grabbing the value from the form?).
Many thanks