Skip Navigation

[Résolu] Custom field date is changed from January 9, 2017 to 20170109 on front end

This support ticket is created Il y a 7 années et 3 mois. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

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 32 réponses, has 2 voix.

Last updated by seanN-5 Il y a 7 années et 3 mois.

Assisted by: Minesh.

Auteur
Publications
#476627

I am trying to: Display the date in a custom field exactly as entered and not converted to a string.

I visited this URL: hidden link

I expected to see: January 9, 2017

Instead, I got: 20170109

#476883

Minesh
Supporter

Languages: Anglais (English )

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

Hello. Thank you for contacting the Toolset support.

Where and how you are displaying the date field? is your date field created using Types?

More info:
https://toolset.com/documentation/customizing-sites-using-php/functions/#date

#476992
toolset-results-1.jpg
toolset-view-setup.jpg

To rule out any plugin effects I have duplicated what I am trying to do in a Fresh WordPress installation at hidden link. The plugins I am using are:

Visual Composer
Advanced Custom Fields Pro
Toolset

I am using the Genesis Sample theme and have the latest version of WordPress.

1. I have created a custom post type called: Test Events
2. I then created two taxonomies - Class and Event
3. Using Advanced Custom Fields Pro I created a custom Date Field called picker_start_date.
4. I have created 7 posts -3 of the posts have a date prior to today entered in the ACF custom field (picker_start_date) and 4 have a date entered that is after today. All have a publish date of today.

I then created a new View (Home Page Display Test). In the query section I have the following set:

Content Selection: Test Events
Ordering: order by Field - picker_start_date Ascending As a number

Query Filter: Select items with field: picker_start_date is a DATE greater than or equal TODAY()

My Results: The query is showing the posts starting with oldest date set in picker_date_start.

What I expected: Show the first post after today, then second post after today, etc.

**I have tired changing order by to "as a native field" and "as a string".

#477235

Minesh
Supporter

Languages: Anglais (English )

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

Here I would like to know in what format the date field 'picker_start_date ' stores date in database table?

Types date fields store UNIX timestamp for date field.

1)
Can I have problem URL?

2)
*** 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 would additionally need your permission to de- and re-activate Plugins and the Theme, and to change configurations on the site. This is also a reason the backup is really important. If you agree to this, please use the form fields I have enabled below to provide temporary access details (wp-admin and FTP).

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

#477384

Minesh
Supporter

Languages: Anglais (English )

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

I've added following code to your current theme's functions.php file:

function acf_formatted_date_shortcode ( $atts ) {
      // default to today if date missing
    $args = shortcode_atts( array (
        'date'      => date( "Ymd", time() ),
        ), $atts );
    return date( "F d,Y", strtotime($args['date']) );
}
add_shortcode( 'acf_formatted_date', 'acf_formatted_date_shortcode' );

And then I called the above shortcode in your view as given under:

[acf_formatted_date date='[wpv-post-field name="picker_start_date"]']<br/>

You can see now desired results and you can change the format as you desired 🙂

Have a great weekend 🙂

#477388

Thank you. The Date looks better but looks like I still need a space after comma.

December 14,2016 should be December 14, 2016

My original issue still remains as it relates to the query. I have limited the query to only show 5 results.

Using filter picker_start_date is a DATE greater than or equal TODAY()

I would expect it to show only events that occur after today (in the following order).

After Today Event 1
After Today Event 2
After Today Event 3
After Today Event 4

The Before events should not be showing as the picker_start_date value (date) for these items is before todays date.

**One other issue Id like to resolve is the formatting of the Time. I would like it to display as: 3:00 pm instead of 15:00:00.

Thank you.

#477430

Minesh
Supporter

Languages: Anglais (English )

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

Could you please check now.

I've added wpv_fitler_query hook to filter your posts and also I've added another shortcode to convert 24 hours time to 12 hours time with AM/PM.

To convert the time:

add_shortcode( 'acf_formatted_time', 'acf_time_convert' );
function acf_time_convert( $atts ) {

     $args = shortcode_atts( array (
        'time'      => '',
        ), $atts );

    return date("g:i a", strtotime($args['time']));
}

To filter the posts - picker_start_date is a DATE greater than or equal TODAY():

add_filter('wpv_filter_query', 'remove_past_events', 10, 3);

function remove_past_events($query_args, $view_settings, $view_id) {

if($view_id == 26) {

$query_args['meta_query'][] = array(array('key' => 'picker_start_date',

// Check the start date field

'value' => current_time('Ymd'),

// Set today's date (note the similar format)

'compare' => '>=',

// Return the ones greater than today's date

'type' => 'NUMERIC,' // Let WordPress know we're working with numbers

));
}

return $query_args;
}

I hope this is exactly the solution you were looking for.

Have a great weekend. 🙂

#477439

That worked perfect Minesh. Thank you.

Just curious why the query did not work off of the View filter. Is it because I'm using Advanced Custom Fields for pickerstart_date instead of the Toolset native custom field?

#477571

Having trouble transferring this to the production site, so reopening ticket. I'll post login details in a private message.

#477790

I transferred what you did over to the production site and its not working there.

I'm using this to pull in posts for Events and for Classes, so I've created two views: one for Events and one for Classes. Here is the code that I am using for each

//* Query Posts for Home Page Events
add_filter('wpv_filter_query', 'remove_past_events', 10, 3);

function remove_past_events($query_args, $view_settings, $view_id) {

if($view_id == 16430) {

$query_args['meta_query'][] = array(array('key' => 'start_date', // Check the start date field

'value' => current_time('Ymd'), // Set today's date (note the similar format)
'compare' => '>=', // Return the ones greater than today's date
'type' => 'NUMERIC,' // Let WordPress know we're working with numbers

));

}

return $query_args;

}

//* Query Posts for Home Page Classes
add_filter('wpv_filter_query', 'remove_past_classes', 10, 3);

function remove_past_classes($query_args, $view_settings, $view_id) {

if($view_id == 16435) {

$query_args['meta_query'][] = array(array('key' => 'start_date', // Check the start date field

'value' => current_time('Ymd'), // Set today's date (note the similar format)
'compare' => '>=', // Return the ones greater than today's date
'type' => 'NUMERIC,' // Let WordPress know we're working with numbers

));

}

return $query_args;

}

Both are returning "No events found".

**Wordpress login and FTP to follow.

#477792

How do I send a private message to send you the login details?

#478039

Minesh
Supporter

Languages: Anglais (English )

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

Hi Sean - due to weekend I was not available.

1)
Please share problem URL of your live site.

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

#478223

Minesh
Supporter

Languages: Anglais (English )

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

Unfortunately wp-admin user/pass not working at this end. Could you please resend it again after checking once.

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

#478243

Minesh
Supporter

Languages: Anglais (English )

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

Well - I see some issue with date format, what date format you are using here?

Could you please set correct test dates for events so I can look into it?

For now I've removed the taxonomy filter but once we set the date and also I see image is not displaying with the view:
=> hidden link

Could you please give me real test dates with same date format set as previous site.

#478246

Image not showing because the particular events its pulling do not have images associated with them.

Let me look at the date question and respond back shortly.

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.