Home Forums Plugin Support WP User Frontend Pro Need a date field for post, not custom field

This topic is: resolved

Tagged: ,

This topic contains 11 replies, has 6 voices, and was last updated by  gary 4 years, 1 month ago.

Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • #2596

    darrelly84
    Participant
    Post count: 5

    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.

    #2604

    Tareq Hasan
    Keymaster
    Post count: 2831

    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]

    #2654

    darrelly84
    Participant
    Post count: 5

    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.

    #2665

    Tareq Hasan
    Keymaster
    Post count: 2831

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

    #2713

    darrelly84
    Participant
    Post count: 5

    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?

    #2717

    Tareq Hasan
    Keymaster
    Post count: 2831

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

    #2721

    darrelly84
    Participant
    Post count: 5
    This reply has been marked as private.
    #2743

    Tareq Hasan
    Keymaster
    Post count: 2831

    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.

    #13581

    Danilo
    Participant
    Post count: 43

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

    #27369

    Ben
    Member
    Post count: 14

    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

    #28193

    Sekander Badsha
    Member
    Post count: 2067

    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]

    #35157

    gary
    Member
    Post count: 1

    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 12 posts - 1 through 12 (of 12 total)

The topic ‘Need a date field for post, not custom field’ is closed to new replies.