Skip Navigation

[Gelöst] Edit post date in forms

This support ticket is created vor 2 Jahre, 11 Monate. There's a good chance that you are reading advice that it now obsolete.

Dies ist das technische Support-Forum für Toolset – eine Suite von Plugins zur Entwicklung von WordPress-Websites ohne PHP-Pogrammierung.

Jeder kann in diesem Forum lesen, aber nur Toolset-Kunden können darin Beiträge veröffentlichen. Der Toolset-Support arbeitet 6 Tage pro Woche, 19 Stunden pro Tag.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 9 Antworten, has 2 Stimmen.

Last updated by Minesh vor 2 Jahre, 11 Monate.

Assigned support staff: Minesh.

Author
Artikel
#1683049

How can I change the post date of a post in the front-end (form)?
This field is not available.

#1683563

Minesh
Supporter

Languages: Englisch (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

Basically, you can update the default post date using the Toolset form hook: cred_save-data

More info:
=> https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data

But I would like to know what date you want to update? Do you want to update with current date or any other date?

#1683639

With other date.
Generic date-field in form.
This generic field should be pre-assigned with the original post-date.

#1683643

Minesh
Supporter

Languages: Englisch (English )

Timezone: Asia/Kolkata (GMT+05:30)

Can you please share the problem URL where you added your form and share access details.

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I have set the next reply to private which means only you and I have access to it.

#1688147

I found the solution in another tick.
Now I want to set the default value of the generic field in the form. I tried the following. But that doesn't work.

[credform]
<div class="form-group">
<label>Beitrags-Datum</label>
[cred_generic_field type='date' field='mod-date']
{"default":"[wpv-post-field name='post_date']", "required":1 }
[/cred_generic_field]

#1688651

Minesh
Supporter

Languages: Englisch (English )

Timezone: Asia/Kolkata (GMT+05:30)

The thing is that Types stores the custom date and generic date field value as numeric as Unix timestamp.

And the default "post_date" field value is saved as a date. If you can tell me:
- Are you using post add/edit form?
- What date you want to set as default date?

#1689169

I want to change the post date.
This should work both when creating and editing.
I found out how to change the post date via a generic field.
It is now a matter of defining the default value of the generic field.
When creating, this should be the current date.
When editing, the previously saved post date.

#1689655

Minesh
Supporter

Languages: Englisch (English )

Timezone: Asia/Kolkata (GMT+05:30)

Basically, to update the post date from the data value coming from the generic date field, you can uses the Toolset form's hook: cred_save_data
=> https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data

For example:

add_action('cred_save_data', 'func_update_post_date',10,2);
function func_update_post_date($post_id, $form_data) {
    // if a specific form
    if ($form_data['id']==999999) {

        $timestamp = $_POST['mod-date'];
        $date = date('Y-m-d H:i:s', $timestamp);
        if(isset($timestamp)){
            $args = array(
                'ID'           => $post_id,
                'post_date' => $date
            );
             wp_update_post( $args );
        }
    }
}

More help:
https://codex.wordpress.org/Function_Reference/wp_update_post

#1690405

This is not my question!
As I wrote earlier, I found this code myself.

I want to know how to use the default value of a generic date field
a) the current date
b) another field value
can prove.

#1691331

Minesh
Supporter

Languages: Englisch (English )

Timezone: Asia/Kolkata (GMT+05:30)

To set the default date to generic field.

You should add the following shortcode to your current theme's functions.php file
or
"Custom Code" section offered by Toolset:
=> https://toolset.com/documentation/adding-custom-code/using-toolset-to-add-custom-code/

function func_return_current_time($atts) {
     return time();
}
add_shortcode("wpv-current-date", "func_return_current_time");

And then edit your Toolset form and adjust your date generic field as given under:

[cred_generic_field type='date' field='mod-date']
{
"default":"[wpv-current-date]",
 "required":1
 }
[/cred_generic_field]

You need to make sure that you are returning the Unix-timestamp to the "default" attribute of your date generic field.

Das Forum „Toolset Professioneller Support“ ist für neue Themen und Antworten geschlossen.