Support

Search results for ""

Sorry, no results found. Perhaps you would like to search the documentation?
All Topics
roy

Inline Editing of Dates still not working

I have a “Custom Field” with a Field Type of “Date”.

When I enable Custom Field editing in 3.2 and click to edit the date, I am given the numeric Unix date-stamp instead of the date. If I input a date, it doesn’t work.

Rather than give me the raw numeric date-stamp, can you let me edit the date in the format I specified in Admin Columns? I don’t need you to validate the date I enter, just let me enter a date and let the chips fall where they may if I enter a bad date.

5 years, 9 months ago
Tobias
Developer

The challenge with dates is that they can be stored is so many different ways. A lot of plugins has their own custom format, some use “unix timestamp”, “ISO format”, or anything custom with time added for example.

We do not want to store a date that’s not 100% correct. The way to solve this is to build in support for specific custom field plugins. Like we did with Advanced Custom Fields, they store the date in a predefined format.

Even if we would use the display format for you to enter the date, we do not know the actual stored format. If we set the default to an “ISO format” your date would probably not correspond with the other dates and could cause isssues with your theme.

For us the solution is by building better integration with other plugins, like ACF, Pods and Types. That’s next on our list.

But maybe we could also add a filter which you can use to set your own predefined date format in your theme. I will have a look a that.

5 years, 9 months ago
Tobias
Developer

I made it work. You can now modify the value right before it’s stored by inline edit. With an added filter you can change the date format very easily. In the example below all inputed values will be converted to a timestamp value.

And I added a filter so you can use a datepicker instead of a text field.

These are the two filters that we will add in version 3.2.1:
'cac/inline-edit/ajax-column-save/value'
'cacie/inline_edit/options'

This example does not work on the current release yet!

Full example:


/**
 * Inline Edit: Changes custom field date format from YYYYMMDD to a timestamp
 *
 */
function acpdemo_set_custom_field_date_store_format( $value, $column ) {
    if ( $column->is_type( 'meta' ) && $column->is_field_type( 'date' ) ) {
        $value = $column->get_timestamp( $value ); // convert to timestamp
    }
    return $value;
}
add_filter( 'cac/inline-edit/ajax-column-save/value', 'acpdemo_set_custom_field_date_store_format', 10, 2 );

/**
 * Inline Edit: change custom field type "date" from a text field to a datepicker
 *
 */
function acpdemo_set_inline_edit_custom_field_to_datepicker( $editable, $column ) {
    if ( 'column-meta' === $column['type'] && 'date' == $column['field_type'] ) {
        $editable['type'] = 'date';
    }
    return $editable;
}
add_filter( 'cacie/inline_edit/options', 'acpdemo_set_inline_edit_custom_field_to_datepicker', 10, 2 );

When version 3.2.1 is released, I will add this example to the documentation.

– Tobias

5 years, 9 months ago
roy

Thanks!

5 years, 9 months ago
roy

Will the Column object include the post-type?

if ( $column->post_type == ‘my_custom_type’) {
yada yada yada
}

5 years, 9 months ago
Tobias
Developer

The $column object contains all the methods you need, including it’s storage model which holds the post_type.

You can get the post_type like so:
$column->get_post_type();

We have very good inline documentation in the code. If you want to learn more about the available column methods I would recommend having a look at the CPAC_Column class.

5 years, 9 months ago
roy

Sweet, thanks!

5 years, 9 months ago

You must be logged in to reply to this topic.