Skip Navigation

[Resolved] edit the post published date in a form

This support ticket is created 6 years ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 8 replies, has 2 voices.

Last updated by Christian Cox 5 years, 11 months ago.

Assisted by: Christian Cox.

Author
Posts
#1191529

Hi - I'm trying to figure out how to edit the post published date in a form. This is what I came up with ..

<div class="form-group">
<label>Post Publish Date</label>
[cred_field field="wpv-post-date" class="form-control" output="bootstrap"]
</div>

But I keep getting .. "There is a problem with wpv-post-date field. Please check CRED form."

You can see the problem on this page ... hidden link

#1191693

Hi, there's not a built-in way to do this in Forms but another ticket here in the forum discusses a custom solution for this problem using a generic field and the Forms API:
https://toolset.com/forums/topic/set-publish-date-of-post/

Let me know if you have questions about that.

#1198210
2019-02-10_11-06-40.jpg

Hi Christian - I tried the code that you provide in the link above, but its not working for me. I'm not a JS programmer so I'm probably missing something very basic. See the uploaded screen shot. You can access the edit form at hidden link. I've been testing with the record called "Along the Charles River" I can provide you access to the WP site if you are willing to help me out with this. Thank you in advance, Mark

#1198219
2019-02-10_11-24-36.jpg

Here is the Custom Field being used (it is getting set just fine in the form)

#1198238

Three things:
1. The code you have now in the JS editor is actually PHP code, so it belongs somewhere else. You can place it in your child theme's functions.php file, or you can add it to a new custom code snippet in Toolset > Settings > Custom code.
2. In the add_action line, you should replace 'set_sort_date' with the name of the function, not the field slug. This line tells WordPress to listen for the cred_save_data event, and when it happens, trigger the corresponding function. So yours should be set_post_date_to:

add_action('cred_save_data', 'set_post_date_to', 100, 3);

3. The string status 'published' should actually be 'publish': https://codex.wordpress.org/Post_Status

#1198268
2019-02-10_16-46-19.jpg
2019-02-10_16-38-28.jpg

Hi Christian:

Thank you for explaining. I made the three changes (see the Toolset custom code screen shot). Other than removing the code from the JS panel, I didn't change the cred form.

But still is not working. I would be grateful for any help.

Also, another dumb question - how do I ensure that this function only affects this one post form (and not other post forms).

I know that this type of coding help is beyond the call. So thank you very very much.

Mark

#1198278

But still is not working. I would be grateful for any help.
It looks like you are using an actual custom field instead of a generic field. An actual custom field should use the wpcf- prefix in the slug. So it should be this instead:

$newDate = $_POST['wpcf-set-sort-date']['datetime'] . ' 00:00:00';

Also, another dumb question - how do I ensure that this function only affects this one post form (and not other post forms).

That's what the 890 does in your code. It checks to confirm the Form ID before continuing with the rest of the code.

if( $form_data['id'] == 890 ) ...

So you should confirm that the Form ID 890 matches the Form you are submitting.

If those two things don't solve the problem, I'll need to take a closer look.

#1198285

Hi Christian:

That did the trick! Just one more question ... there are post two post forms that I need this to work in 890 and 512. What is the syntax for that IF statement in this case.

Thank you for your patience with me. Its rare I experience this high a level of tech support.

Mark

#1198789

You can add another form ID to the "if" condition like this:

...
if( $form_data['id'] == 890 || $form_data['id'] == 512 ) {
...