• Kevin

    (@wp18nkevin)


    Hi there,

    I was wondering whether I can use some filter to format the date while importing? I have a custom field “Date”, and I would like to store them in database as a time stamp. It’s hard to ensure multiple user to use the correct date format in .csv file before import.
    or
    Is it possible to convert the meta “key” to timestamp before compare it in meta query?
    My code to get the post:

    $args = array(
                            'post_type'  => 'calendar',
                            'meta_query' => array(
                                'relation' => 'AND',
                                array(
                                    'key'     => 'Calendar',
                                    'value'   => $calendar,
                                    'compare' => '='
                                ),	        
    
                                array(
                                    'key'     => 'Date',
                                    'value'   => $qdate,
                                    'type'    => 'DATE',
                                    'compare' => '='
                                )
                            )
                        );

    https://wordpress.org/plugins/really-simple-csv-importer/

Viewing 1 replies (of 1 total)
  • J M

    (@hiphopinenglish)

    You will need to get your feet wet by jumping into rs-csv-importer.php and adding your own code. Here is a snippet I’m using to give you an idea:

    if ( $this->column_keys[$key] == '_cm_dob' ) {
        if ( ( $timestamp = strtotime( $value ) ) !== false ) {
            $meta[$this->column_keys[$key]] = $timestamp;
        } else {
            $error->add( 'invalid_date', sprintf( __( 'Invalid date format "%s".', 'cm_lang' ), $value ) );
    }

    You would need to change _cm_dob for the column header you’re using.

Viewing 1 replies (of 1 total)
  • The topic ‘Date Formatting’ is closed to new replies.