Up to 50 percent off

Need a date field for post, not custom field

This topic contains 11 reply and 6 voices, and was last updated by gary 9 years, 9 months ago
Viewing 11 Posts - 1 through 11 (of 11 total)
Author Posts
April 20, 2013 at 3:18 am 2596
gary I'm using the plugin so visitors can make posts from the front end, but I need the date field to be available to posters. I see there's a date in the custom fields section, but I need them to be able to change the actual post date. Is this possible? I don't see the option here.
April 20, 2013 at 4:25 am 2604
Tareq Hasan Tareq Hasan

There isn’t any option right now. But you can take advantage of the filter system of the plugin. Add a datepicker custom field to the form and name the meta key to `post_date`. Now drop this code to your themes function.php. Now it’ll take that date as the post date input.

[php]
function wpufe_set_custom_post_date( $args ) {
if ( isset( $_POST[‘post_date’] ) ) {
$args[‘post_date’] = gmdate( ‘Y-m-d H:i:s’, strtotime( $_POST[‘post_date’] ) );
}

return $args;
}

add_filter( ‘wpuf_add_post_args’, ‘wpufe_set_custom_post_date’ );
[/php]

April 22, 2013 at 4:04 am 2654
darrelly84 darrelly84

That sounds promising, but it’s not working for me. When submitting the form, the date is displayed as a custom field in the body, and the post date is set to Jan 1, 1970. It’s not picking the date I’ve input on the form.

April 22, 2013 at 8:41 am 2665
Tareq Hasan Tareq Hasan

In the form editor, set the date format to yy-mm-dd. I just tested and it works perfectly.

April 22, 2013 at 5:30 pm 2713
darrelly84 darrelly84

I hate to keep bugging you, but this could kill my whole project if this doens’t work, but I think we’re close. After changing the date format, I’m able to submit, but the post has today’s date on it, rather than the date from the picker. At least it’s not displaying the 1970 date anymore. Any other thoughts?

April 22, 2013 at 6:07 pm 2717
Tareq Hasan Tareq Hasan

I don’t understand whats wrong going in your setup. Can you send login details in a private reply?

April 22, 2013 at 6:16 pm 2721
darrelly84 darrelly84 This reply has been marked as private.
April 22, 2013 at 9:14 pm 2743
Tareq Hasan Tareq Hasan

I specifically instructed you to give the meta key post_date. The code doesn’t work or won’t work if you give any other meta key. Check now, I guess its working.

December 10, 2013 at 9:38 pm 13581
Danilo Danilo

Hi.
Is possible to put current date and time if custom field is leave blank by the user?

September 24, 2014 at 7:03 am 27369
Ben Ben

1.) If no date is entered, it enters January 1st 1970. That’s no good. 🙂

2.) If pending approval, once you view the product, its publish date is set to Immediately, rather than the date the person entered.

It’s a good start, but it needs fixing first. Please advise! Paid purchaser of the pro version here 😉

Ben

October 12, 2014 at 12:00 pm 28193
Sekander Badsha Sekander Badsha

Hello Ben,
If you see the above code, you will see that there is no default date is given. So it takes the default time of PHP. You can set the default time to current by placing a check for if empty.
Follow the below code to understand better.

[php]
function wpufe_set_custom_post_date( $args ) {
if ( isset( $_POST[‘post_date’] ) ) {
$args[‘post_date’] = !empty( $_POST[‘post_date’] ) ? gmdate( ‘Y-m-d H:i:s’, strtotime( $_POST[‘post_date’] ) ) : current_time( ‘mysql’ );
}

return $args;
}

add_filter( ‘wpuf_add_post_args’, ‘wpufe_set_custom_post_date’ );
[/php]

January 28, 2015 at 6:21 am 35157
gary gary

I have the form with post_date and I have the code added to my functions.php. The date is transferring between the published on date and the WPUF custom field when I am in the post edit screen in wordpress, but the date will not save when changed in the front end form. I think it is just being overwritten back to the published on date. Am I missing something?? Thanks.

Viewing 11 Posts - 1 through 11 (of 11 total)